Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Side by Side Diff: client/logdog/butlerlib/bootstrap/bootstrap_test.go

Issue 1906023002: LogDog: Add project namespace to Butler/Collector. (Closed) Base URL: https://github.com/luci/luci-go@logdog-project-archivist
Patch Set: Rebase? Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 bootstrap 5 package bootstrap
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "testing" 9 "testing"
10 10
11 "github.com/luci/luci-go/client/environ" 11 "github.com/luci/luci-go/client/environ"
12 "github.com/luci/luci-go/client/logdog/butlerlib/streamclient" 12 "github.com/luci/luci-go/client/logdog/butlerlib/streamclient"
13 "github.com/luci/luci-go/client/logdog/butlerlib/streamproto" 13 "github.com/luci/luci-go/client/logdog/butlerlib/streamproto"
14 » "github.com/luci/luci-go/common/logdog/types" 14
15 » "github.com/luci/luci-go/common/testing/assertions" 15 » . "github.com/luci/luci-go/common/testing/assertions"
16 . "github.com/smartystreets/goconvey/convey" 16 . "github.com/smartystreets/goconvey/convey"
17 ) 17 )
18 18
19 type sentinelClient struct{} 19 type sentinelClient struct{}
20 20
21 func (*sentinelClient) NewStream(f streamproto.Flags) (streamclient.Stream, erro r) { return nil, nil } 21 func (*sentinelClient) NewStream(f streamproto.Flags) (streamclient.Stream, erro r) { return nil, nil }
22 22
23 func TestBootstrap(t *testing.T) { 23 func TestBootstrap(t *testing.T) {
24 Convey(`A test Environment`, t, func() { 24 Convey(`A test Environment`, t, func() {
25 reg := &streamclient.Registry{} 25 reg := &streamclient.Registry{}
26 regSpec := "" 26 regSpec := ""
27 regErr := error(nil) 27 regErr := error(nil)
28 reg.Register("test", func(spec string) (streamclient.Client, err or) { 28 reg.Register("test", func(spec string) (streamclient.Client, err or) {
29 regSpec = spec 29 regSpec = spec
30 return &sentinelClient{}, regErr 30 return &sentinelClient{}, regErr
31 }) 31 })
32 32
33 env := environ.Environment{ 33 env := environ.Environment{
34 "IRRELEVANT": "VALUE", 34 "IRRELEVANT": "VALUE",
35 } 35 }
36 36
37 Convey(`With no Butler values will return ErrNotBootstrapped.`, func() { 37 Convey(`With no Butler values will return ErrNotBootstrapped.`, func() {
38 _, err := getFromEnv(env, reg) 38 _, err := getFromEnv(env, reg)
39 So(err, ShouldEqual, ErrNotBootstrapped) 39 So(err, ShouldEqual, ErrNotBootstrapped)
40 }) 40 })
41 41
42 » » Convey(`With a Butler prefix`, func() { 42 » » Convey(`With a Butler project and prefix`, func() {
43 » » » env[EnvStreamProject] = "test-project"
43 env[EnvStreamPrefix] = "butler/prefix" 44 env[EnvStreamPrefix] = "butler/prefix"
44 45
45 » » » Convey(`Yields a Bootstrap with a Prefix and no Client.` , func() { 46 » » » Convey(`Yields a Bootstrap with a Project, Prefix, and n o Client.`, func() {
46 bs, err := getFromEnv(env, reg) 47 bs, err := getFromEnv(env, reg)
47 So(err, ShouldBeNil) 48 So(err, ShouldBeNil)
48 » » » » So(bs.Prefix, ShouldEqual, types.StreamName("but ler/prefix")) 49
49 » » » » So(bs.Client, ShouldBeNil) 50 » » » » So(bs, ShouldResemble, &Bootstrap{
51 » » » » » Project: "test-project",
52 » » » » » Prefix: "butler/prefix",
53 » » » » })
50 }) 54 })
51 55
52 Convey(`And a stream server path`, func() { 56 Convey(`And a stream server path`, func() {
53 env[EnvStreamServerPath] = "test:client:params" 57 env[EnvStreamServerPath] = "test:client:params"
54 58
55 Convey(`Yields a Bootstrap with a Prefix and Cli ent.`, func() { 59 Convey(`Yields a Bootstrap with a Prefix and Cli ent.`, func() {
56 bs, err := getFromEnv(env, reg) 60 bs, err := getFromEnv(env, reg)
57 So(err, ShouldBeNil) 61 So(err, ShouldBeNil)
58 » » » » » So(bs.Prefix, ShouldEqual, types.StreamN ame("butler/prefix")) 62
59 » » » » » So(bs.Client, ShouldEqual, &sentinelClie nt{}) 63 » » » » » So(bs, ShouldResemble, &Bootstrap{
64 » » » » » » Project: "test-project",
65 » » » » » » Prefix: "butler/prefix",
66 » » » » » » Client: &sentinelClient{},
67 » » » » » })
60 So(regSpec, ShouldEqual, "client:params" ) 68 So(regSpec, ShouldEqual, "client:params" )
61 }) 69 })
62 70
63 Convey(`If Client creation fails, will fail.`, f unc() { 71 Convey(`If Client creation fails, will fail.`, f unc() {
64 regErr = errors.New("testing error") 72 regErr = errors.New("testing error")
65 _, err := getFromEnv(env, reg) 73 _, err := getFromEnv(env, reg)
66 » » » » » So(err, assertions.ShouldErrLike, "faile d to create stream client") 74 » » » » » So(err, ShouldErrLike, "failed to create stream client")
67 }) 75 })
68 }) 76 })
77
78 Convey(`With an invalid Butler prefix, will fail.`, func () {
79 env[EnvStreamPrefix] = "_notavaildprefix"
80 _, err := getFromEnv(env, reg)
81 So(err, ShouldErrLike, "failed to validate prefi x")
82 })
83
84 Convey(`With an missing Butler project, will fail.`, fun c() {
85 delete(env, EnvStreamProject)
86 _, err := getFromEnv(env, reg)
87 So(err, ShouldErrLike, "failed to validate proje ct")
88 })
89
90 Convey(`With an invalid Butler project, will fail.`, fun c() {
91 env[EnvStreamProject] = "_notavaildproject"
92 _, err := getFromEnv(env, reg)
93 So(err, ShouldErrLike, "failed to validate proje ct")
94 })
69 }) 95 })
70
71 Convey(`With an invalid Butler prefix, will fail.`, func() {
72 env[EnvStreamPrefix] = "_notavaildprefix"
73 _, err := getFromEnv(env, reg)
74 So(err, assertions.ShouldErrLike, "failed to validate pr efix")
75 })
76
77 }) 96 })
78 } 97 }
OLDNEW
« no previous file with comments | « client/logdog/butlerlib/bootstrap/bootstrap.go ('k') | client/logdog/butlerlib/bootstrap/environment.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698