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

Side by Side Diff: logdog/server/service/config/flag_test.go

Issue 2647083003: LogDog: Use luci_config/server packages for config (Closed)
Patch Set: Comments. Created 3 years, 11 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
« no previous file with comments | « logdog/server/service/config/flag.go ('k') | logdog/server/service/config/opts.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file.
4
5 package config
6
7 import (
8 "errors"
9 "flag"
10 "io/ioutil"
11 "os"
12 "path/filepath"
13 "testing"
14 "time"
15
16 "github.com/golang/protobuf/proto"
17 "github.com/luci/luci-go/common/config/impl/remote"
18 "github.com/luci/luci-go/common/proto/google"
19 "github.com/luci/luci-go/logdog/api/config/svcconfig"
20 "github.com/luci/luci-go/logdog/api/endpoints/coordinator/services/v1"
21 "golang.org/x/net/context"
22 "google.golang.org/grpc"
23
24 . "github.com/luci/luci-go/common/testing/assertions"
25 . "github.com/smartystreets/goconvey/convey"
26 )
27
28 type testServicesClient struct {
29 logdog.ServicesClient
30 cfg logdog.GetConfigResponse
31 err error
32 }
33
34 func (tsc *testServicesClient) GetConfig(context.Context, *google.Empty, ...grpc .CallOption) (
35 *logdog.GetConfigResponse, error) {
36 if tsc.err != nil {
37 return nil, tsc.err
38 }
39 return &tsc.cfg, nil
40 }
41
42 func TestFlag(t *testing.T) {
43 Convey(`A set of config Flags`, t, func() {
44 c := context.Background()
45
46 f := Flags{}
47
48 Convey(`Can parse command-line options.`, func() {
49 fs := flag.NewFlagSet("test", flag.PanicOnError)
50 f.AddToFlagSet(fs)
51
52 So(fs.Parse([]string{
53 "-config-file-path", "test.cfg",
54 "-config-kill-interval", "3m",
55 }), ShouldBeNil)
56 So(f.ConfigFilePath, ShouldEqual, "test.cfg")
57 So(f.KillCheckInterval, ShouldEqual, 3*time.Minute)
58 })
59
60 Convey(`Using a Coordinator client stub`, func() {
61 tsc := testServicesClient{}
62 tsc.cfg.ConfigServiceUrl = "http://example.com"
63 tsc.cfg.ConfigSet = "services/testservice"
64 tsc.cfg.ServiceConfigPath = "configpath.cfg"
65
66 Convey(`Will load configuration from luci-config by defa ult.`, func() {
67 o, err := f.CoordinatorOptions(c, &tsc)
68 So(err, ShouldBeNil)
69 So(o.Config, ShouldHaveSameTypeAs, remote.New("h ttps://example.com", true, nil))
70 })
71
72 Convey(`Will fail to create Options if no config service is specified.`, func() {
73 tsc.cfg.ConfigServiceUrl = ""
74
75 _, err := f.CoordinatorOptions(c, &tsc)
76 So(err, ShouldErrLike, "coordinator does not spe cify a config service")
77 })
78
79 Convey(`Will fail to create Options if no config set is specified.`, func() {
80 tsc.cfg.ConfigSet = ""
81
82 _, err := f.CoordinatorOptions(c, &tsc)
83 So(err, ShouldErrLike, "coordinator does not spe cify a config set")
84 })
85
86 Convey(`Will fail to create Options if no config path is specified.`, func() {
87 tsc.cfg.ServiceConfigPath = ""
88
89 _, err := f.CoordinatorOptions(c, &tsc)
90 So(err, ShouldErrLike, "coordinator does not spe cify a config path")
91 })
92
93 Convey(`When loading from a testing file using a Coordin ator stub.`, func() {
94 tdir, err := ioutil.TempDir("", "configTest")
95 So(err, ShouldBeNil)
96 defer os.RemoveAll(tdir)
97
98 f.ConfigFilePath = filepath.Join(tdir, "config")
99 writeConfig := func(cfg *svcconfig.Config) error {
100 servicePath := filepath.Join(f.ConfigFil ePath, "services", "testservice")
101 os.MkdirAll(servicePath, 0755)
102
103 fd, err := os.Create(filepath.Join(servi cePath, "configpath.cfg"))
104 if err != nil {
105 return err
106 }
107 defer fd.Close()
108
109 return proto.MarshalText(fd, cfg)
110 }
111
112 cfg := &svcconfig.Config{
113 Transport: &svcconfig.Transport{
114 Type: &svcconfig.Transport_Pubsu b{
115 Pubsub: &svcconfig.Trans port_PubSub{
116 Project: "f oo",
117 Topic: "b ar",
118 Subscription: "b az",
119 },
120 },
121 },
122 }
123 So(writeConfig(cfg), ShouldBeNil)
124
125 Convey(`Will fail to load Options if the Coordin ator config could not be fetched.`, func() {
126 tsc := testServicesClient{err: errors.Ne w("test error")}
127 _, err := f.CoordinatorOptions(c, &tsc)
128 So(err, ShouldErrLike, "test error")
129 })
130
131 Convey(`Will load options from the configuration file.`, func() {
132 o, err := f.CoordinatorOptions(c, &tsc)
133 So(err, ShouldBeNil)
134 So(o, ShouldNotBeNil)
135
136 Convey(`Can load configuration from the file.`, func() {
137 m, err := NewManager(c, *o)
138 So(err, ShouldBeNil)
139 So(m.Config(), ShouldResemble, c fg)
140 })
141 })
142 })
143 })
144 })
145 }
OLDNEW
« no previous file with comments | « logdog/server/service/config/flag.go ('k') | logdog/server/service/config/opts.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698