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: tokenserver/appengine/delegation/rpc_import_delegation_configs_test.go

Issue 2575383002: Add server/cache support to gaeconfig. (Closed)
Patch Set: Un-collapse. 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 | « tokenserver/appengine/delegation/rpc_import_delegation_configs.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package delegation 5 package delegation
6 6
7 import ( 7 import (
8 "testing" 8 "testing"
9 9
10 "golang.org/x/net/context" 10 "golang.org/x/net/context"
11 11
12 "github.com/luci/gae/service/info" 12 "github.com/luci/gae/service/info"
13 "github.com/luci/luci-go/appengine/gaetesting" 13 "github.com/luci/luci-go/appengine/gaetesting"
14 "github.com/luci/luci-go/common/clock/testclock" 14 "github.com/luci/luci-go/common/clock/testclock"
15 "github.com/luci/luci-go/common/config"
16 "github.com/luci/luci-go/common/config/impl/memory" 15 "github.com/luci/luci-go/common/config/impl/memory"
16 "github.com/luci/luci-go/luci_config/server/cfgclient/backend/testconfig "
17 admin "github.com/luci/luci-go/tokenserver/api/admin/v1" 17 admin "github.com/luci/luci-go/tokenserver/api/admin/v1"
18 18
19 . "github.com/luci/luci-go/common/testing/assertions" 19 . "github.com/luci/luci-go/common/testing/assertions"
20 . "github.com/smartystreets/goconvey/convey" 20 . "github.com/smartystreets/goconvey/convey"
21 ) 21 )
22 22
23 func TestImportDelegationConfigs(t *testing.T) { 23 func TestImportDelegationConfigs(t *testing.T) {
24 Convey("Works", t, func() { 24 Convey("Works", t, func() {
25 ctx := gaetesting.TestingContext() 25 ctx := gaetesting.TestingContext()
26 ctx, _ = testclock.UseTime(ctx, testclock.TestTimeUTC) 26 ctx, _ = testclock.UseTime(ctx, testclock.TestTimeUTC)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 So(cfg.Revision, ShouldEqual, "780529c8f5e6b219e27482978d792d580 f7d4f9d") 59 So(cfg.Revision, ShouldEqual, "780529c8f5e6b219e27482978d792d580 f7d4f9d")
60 60
61 // Noop import. 61 // Noop import.
62 resp, err = rpc.ImportDelegationConfigs(ctx, nil) 62 resp, err = rpc.ImportDelegationConfigs(ctx, nil)
63 So(err, ShouldBeNil) 63 So(err, ShouldBeNil)
64 So(resp.ImportedConfigs[0].Revision, ShouldEqual, "780529c8f5e6b 219e27482978d792d580f7d4f9d") 64 So(resp.ImportedConfigs[0].Revision, ShouldEqual, "780529c8f5e6b 219e27482978d792d580f7d4f9d")
65 65
66 // Try to import completely broken config. 66 // Try to import completely broken config.
67 ctx = prepareCfg(ctx, `I'm broken`) 67 ctx = prepareCfg(ctx, `I'm broken`)
68 _, err = rpc.ImportDelegationConfigs(ctx, nil) 68 _, err = rpc.ImportDelegationConfigs(ctx, nil)
69 » » So(err, ShouldErrLike, `can't parse config file - line 1.0: unkn own field name`) 69 » » So(err, ShouldErrLike, `line 1.0: unknown field name`)
70 70
71 // Old config is not replaced. 71 // Old config is not replaced.
72 cfg, _ = FetchDelegationConfig(ctx) 72 cfg, _ = FetchDelegationConfig(ctx)
73 So(cfg.Revision, ShouldEqual, "780529c8f5e6b219e27482978d792d580 f7d4f9d") 73 So(cfg.Revision, ShouldEqual, "780529c8f5e6b219e27482978d792d580 f7d4f9d")
74 74
75 // Try to import a config that doesn't pass validation. 75 // Try to import a config that doesn't pass validation.
76 ctx = prepareCfg(ctx, `rules { 76 ctx = prepareCfg(ctx, `rules {
77 name: "rule 1" 77 name: "rule 1"
78 }`) 78 }`)
79 _, err = rpc.ImportDelegationConfigs(ctx, nil) 79 _, err = rpc.ImportDelegationConfigs(ctx, nil)
80 So(err, ShouldErrLike, `validation error - rule #1 ("rule 1"): ' requestor' is required (and 4 other errors)`) 80 So(err, ShouldErrLike, `validation error - rule #1 ("rule 1"): ' requestor' is required (and 4 other errors)`)
81 81
82 // Old config is not replaced. 82 // Old config is not replaced.
83 cfg, _ = FetchDelegationConfig(ctx) 83 cfg, _ = FetchDelegationConfig(ctx)
84 So(cfg.Revision, ShouldEqual, "780529c8f5e6b219e27482978d792d580 f7d4f9d") 84 So(cfg.Revision, ShouldEqual, "780529c8f5e6b219e27482978d792d580 f7d4f9d")
85 }) 85 })
86 } 86 }
87 87
88 func prepareCfg(c context.Context, configFile string) context.Context { 88 func prepareCfg(c context.Context, configFile string) context.Context {
89 » return config.SetImplementation(c, memory.New(map[string]memory.ConfigSe t{ 89 » return testconfig.WithCommonClient(c, memory.New(map[string]memory.Confi gSet{
90 "services/" + info.AppID(c): { 90 "services/" + info.AppID(c): {
91 "delegation.cfg": configFile, 91 "delegation.cfg": configFile,
92 }, 92 },
93 })) 93 }))
94 } 94 }
OLDNEW
« no previous file with comments | « tokenserver/appengine/delegation/rpc_import_delegation_configs.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698