| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package butler | 5 package butler |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "errors" | 9 "errors" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 221 } |
| 222 | 222 |
| 223 func TestConfig(t *testing.T) { | 223 func TestConfig(t *testing.T) { |
| 224 t.Parallel() | 224 t.Parallel() |
| 225 | 225 |
| 226 Convey(`A Config instance`, t, func() { | 226 Convey(`A Config instance`, t, func() { |
| 227 to := testOutput{ | 227 to := testOutput{ |
| 228 maxSize: 1024, | 228 maxSize: 1024, |
| 229 } | 229 } |
| 230 conf := Config{ | 230 conf := Config{ |
| 231 » » » Output: &to, | 231 » » » Output: &to, |
| 232 » » » Prefix: "unit/test", | 232 » » » Prefix: "unit/test", |
| 233 » » » Project: "test-project", |
| 234 » » » Secret: types.PrefixSecret(bytes.Repeat([]byte{0x55}, t
ypes.PrefixSecretLength)), |
| 233 } | 235 } |
| 234 | 236 |
| 235 Convey(`Will validate.`, func() { | 237 Convey(`Will validate.`, func() { |
| 236 So(conf.Validate(), ShouldBeNil) | 238 So(conf.Validate(), ShouldBeNil) |
| 237 }) | 239 }) |
| 238 | 240 |
| 239 Convey(`Will not validate with a nil Output.`, func() { | 241 Convey(`Will not validate with a nil Output.`, func() { |
| 240 conf.Output = nil | 242 conf.Output = nil |
| 241 So(conf.Validate(), ShouldErrLike, "an Output must be su
pplied") | 243 So(conf.Validate(), ShouldErrLike, "an Output must be su
pplied") |
| 242 }) | 244 }) |
| 243 | 245 |
| 244 Convey(`Will not validate with an invalid Prefix.`, func() { | 246 Convey(`Will not validate with an invalid Prefix.`, func() { |
| 245 conf.Prefix = "!!!!invalid!!!!" | 247 conf.Prefix = "!!!!invalid!!!!" |
| 246 » » » So(conf.Validate(), ShouldErrLike, "invalid Prefix") | 248 » » » So(conf.Validate(), ShouldErrLike, "invalid prefix") |
| 249 » » }) |
| 250 |
| 251 » » Convey(`Will not validate with an invalid Project.`, func() { |
| 252 » » » conf.Project = "!!!!invalid!!!!" |
| 253 » » » So(conf.Validate(), ShouldErrLike, "invalid project") |
| 247 }) | 254 }) |
| 248 }) | 255 }) |
| 249 } | 256 } |
| 250 | 257 |
| 251 // mkb is shorthand for "make Butler". It calls "new" and panics if there is | 258 // mkb is shorthand for "make Butler". It calls "new" and panics if there is |
| 252 // an error. | 259 // an error. |
| 253 func mkb(c context.Context, config Config) *Butler { | 260 func mkb(c context.Context, config Config) *Butler { |
| 254 b, err := New(c, config) | 261 b, err := New(c, config) |
| 255 if err != nil { | 262 if err != nil { |
| 256 panic(err) | 263 panic(err) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 267 teeStderr := bytes.Buffer{} | 274 teeStderr := bytes.Buffer{} |
| 268 to := testOutput{ | 275 to := testOutput{ |
| 269 maxSize: 1024, | 276 maxSize: 1024, |
| 270 } | 277 } |
| 271 | 278 |
| 272 conf := Config{ | 279 conf := Config{ |
| 273 Output: &to, | 280 Output: &to, |
| 274 OutputWorkers: 1, | 281 OutputWorkers: 1, |
| 275 BufferLogs: false, | 282 BufferLogs: false, |
| 276 Prefix: "unit/test", | 283 Prefix: "unit/test", |
| 284 Project: "test-project", |
| 285 Secret: types.PrefixSecret(bytes.Repeat([]byte{0x
55}, types.PrefixSecretLength)), |
| 277 TeeStdout: &teeStdout, | 286 TeeStdout: &teeStdout, |
| 278 TeeStderr: &teeStderr, | 287 TeeStderr: &teeStderr, |
| 279 } | 288 } |
| 280 | 289 |
| 281 Convey(`Will error if an invalid Config is passed.`, func() { | 290 Convey(`Will error if an invalid Config is passed.`, func() { |
| 282 conf.Output = nil | 291 conf.Output = nil |
| 283 So(conf.Validate(), ShouldNotBeNil) | 292 So(conf.Validate(), ShouldNotBeNil) |
| 284 | 293 |
| 285 _, err := New(c, conf) | 294 _, err := New(c, conf) |
| 286 So(err, ShouldNotBeNil) | 295 So(err, ShouldNotBeNil) |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 tss.onNext = func() { | 531 tss.onNext = func() { |
| 523 panic("test panic") | 532 panic("test panic") |
| 524 } | 533 } |
| 525 | 534 |
| 526 b := mkb(c, conf) | 535 b := mkb(c, conf) |
| 527 b.AddStreamServer(tss) | 536 b.AddStreamServer(tss) |
| 528 So(b.Wait(), ShouldErrLike, "test panic") | 537 So(b.Wait(), ShouldErrLike, "test panic") |
| 529 }) | 538 }) |
| 530 }) | 539 }) |
| 531 } | 540 } |
| OLD | NEW |