| Index: server/config/caching/proccache_test.go
|
| diff --git a/server/config/caching/proccache_test.go b/server/config/caching/proccache_test.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ab51db4525442e2c6f9b9bbce2f6913cbb58fad5
|
| --- /dev/null
|
| +++ b/server/config/caching/proccache_test.go
|
| @@ -0,0 +1,80 @@
|
| +// Copyright 2015 The LUCI Authors. All rights reserved.
|
| +// Use of this source code is governed under the Apache License, Version 2.0
|
| +// that can be found in the LICENSE file.
|
| +
|
| +package caching
|
| +
|
| +import (
|
| + "testing"
|
| + "time"
|
| +
|
| + "github.com/luci/luci-go/common/clock/testclock"
|
| + "github.com/luci/luci-go/common/config/impl/memory"
|
| + "github.com/luci/luci-go/common/data/caching/proccache"
|
| + "github.com/luci/luci-go/server/config"
|
| + "github.com/luci/luci-go/server/config/testconfig"
|
| +
|
| + "golang.org/x/net/context"
|
| +
|
| + //. "github.com/luci/luci-go/common/testing/assertions"
|
| + . "github.com/smartystreets/goconvey/convey"
|
| +)
|
| +
|
| +func TestProcCache(t *testing.T) {
|
| + t.Parallel()
|
| +
|
| + Convey(`A testing setup`, t, func() {
|
| + c := context.Background()
|
| + c, tc := testclock.UseTime(c, testclock.TestTimeLocal)
|
| +
|
| + mbase := map[string]memory.ConfigSet{
|
| + "projects/foo": {
|
| + "file": "content",
|
| + },
|
| + }
|
| +
|
| + var pc proccache.Cache
|
| + c = proccache.Use(c, &pc)
|
| +
|
| + // Install our backend: memory backed by cache backed by force error.
|
| + var backend config.Backend
|
| + lcp := testconfig.LocalClientProvider{
|
| + Base: memory.New(mbase),
|
| + }
|
| + backend = &config.ClientBackend{
|
| + Provider: &lcp,
|
| + }
|
| + backend = ProcCache(backend, time.Hour)
|
| + c = config.WithBackend(c, backend)
|
| +
|
| + Convey(`Will store and cache a value.`, func() {
|
| + var s string
|
| + So(config.Get(c, config.AsService, "projects/foo", "file", config.String(&s), nil), ShouldBeNil)
|
| + So(s, ShouldEqual, "content")
|
| +
|
| + delete(mbase, "projects/foo")
|
| +
|
| + // Cached.
|
| + So(config.Get(c, config.AsService, "projects/foo", "file", config.String(&s), nil), ShouldBeNil)
|
| + So(s, ShouldEqual, "content")
|
| +
|
| + // Expires, records lack of config.
|
| + tc.Add(time.Hour)
|
| +
|
| + So(config.Get(c, config.AsService, "projects/foo", "file", config.String(&s), nil),
|
| + ShouldEqual, config.ErrNoConfig)
|
| +
|
| + // Re-add, still no config.
|
| + mbase["projects/foo"] = memory.ConfigSet{
|
| + "file": "content",
|
| + }
|
| + So(config.Get(c, config.AsService, "projects/foo", "file", config.String(&s), nil),
|
| + ShouldEqual, config.ErrNoConfig)
|
| +
|
| + // "No config" expires, config is back.
|
| + tc.Add(time.Hour)
|
| + So(config.Get(c, config.AsService, "projects/foo", "file", config.String(&s), nil), ShouldBeNil)
|
| + So(s, ShouldEqual, "content")
|
| + })
|
| + })
|
| +}
|
|
|