Skip to content

Commit

Permalink
Minor changes/fixes to jujuclienttesting
Browse files Browse the repository at this point in the history
- Rename NewMemControllerStore to NewMemStore
- Rename inMemory to MemStore (exported)
- Export fields of MemStore to enable unit tests
  to initialise test stores succinctly
- Change type of Models and Accounts fields of
  MemStore to store pointer-to-struct for models
  and accounts; we weren't persisting updates.
  • Loading branch information
axw committed Feb 15, 2016
1 parent ea4ad70 commit 5686c67
Show file tree
Hide file tree
Showing 21 changed files with 89 additions and 90 deletions.
4 changes: 2 additions & 2 deletions apiserver/addresser/addresser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func testingEnvConfig(c *gc.C) *config.Config {
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(
modelcmd.BootstrapContext(coretesting.Context(c)), configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
"dummycontroller", environs.PrepareForBootstrapParams{Config: cfg},
)
c.Assert(err, jc.ErrorIsNil)
Expand All @@ -303,7 +303,7 @@ func mockTestingEnvConfig(c *gc.C) *config.Config {
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(
modelcmd.BootstrapContext(coretesting.Context(c)), configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
"dummycontroller", environs.PrepareForBootstrapParams{Config: cfg},
)
c.Assert(err, jc.ErrorIsNil)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/common/modelwatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func testingEnvConfig(c *gc.C) *config.Config {
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(
modelcmd.BootstrapContext(testing.Context(c)), configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
"dummycontroller", environs.PrepareForBootstrapParams{Config: cfg},
)
c.Assert(err, jc.ErrorIsNil)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/imagemetadata/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *funcSuite) SetUpTest(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
s.env, err = environs.Prepare(
envtesting.BootstrapContext(c), configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
"dummycontroller", environs.PrepareForBootstrapParams{Config: cfg},
)
c.Assert(err, jc.ErrorIsNil)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/imagemetadata/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func testConfig(c *gc.C) *config.Config {
c.Assert(err, jc.ErrorIsNil)
_, err = environs.Prepare(
envtesting.BootstrapContext(c), configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
"dummycontroller", environs.PrepareForBootstrapParams{Config: cfg},
)
c.Assert(err, jc.ErrorIsNil)
Expand Down
2 changes: 1 addition & 1 deletion apiserver/imagemetadata/updatefrompublished_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *imageMetadataUpdateSuite) TestUpdateFromPublishedImagesForProviderWithN
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(
modelcmd.BootstrapContext(testing.Context(c)), configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
"dummycontroller", environs.PrepareForBootstrapParams{Config: cfg},
)
c.Assert(err, jc.ErrorIsNil)
Expand Down
2 changes: 1 addition & 1 deletion cmd/juju/controller/listcontrollers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CONTROLLER MODEL USER SERVER
`[1:]

s.store = jujuclienttesting.NewMemControllerStore()
s.store = jujuclienttesting.NewMemStore()
s.assertListControllers(c)
}

Expand Down
3 changes: 0 additions & 3 deletions cmd/jujud/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/juju/juju/constraints"
"github.com/juju/juju/environs"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/environs/configstore"
"github.com/juju/juju/environs/filestorage"
"github.com/juju/juju/environs/simplestreams"
sstesting "github.com/juju/juju/environs/simplestreams/testing"
Expand All @@ -58,8 +57,6 @@ import (
"github.com/juju/juju/version"
)

var _ = configstore.Default

// We don't want to use JujuConnSuite because it gives us
// an already-bootstrapped environment.
type BootstrapSuite struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/plugins/juju-metadata/toolsmetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *ToolsMetadataSuite) SetUpTest(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(
modelcmd.BootstrapContextNoVerify(coretesting.Context(c)),
configstore.NewMem(), jujuclienttesting.NewMemControllerStore(), cfg.Name(),
configstore.NewMem(), jujuclienttesting.NewMemStore(), cfg.Name(),
environs.PrepareForBootstrapParams{Config: cfg},
)
c.Assert(err, jc.ErrorIsNil)
Expand Down
2 changes: 1 addition & 1 deletion environs/imagemetadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (s *ImageMetadataSuite) env(c *gc.C, imageMetadataURL, stream string) envir
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(
envtesting.BootstrapContext(c), configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg},
)
c.Assert(err, jc.ErrorIsNil)
Expand Down
4 changes: 2 additions & 2 deletions environs/jujutest/livetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (t *LiveTests) SetUpSuite(c *gc.C) {
t.CleanupSuite.SetUpSuite(c)
t.TestDataSuite.SetUpSuite(c)
t.ConfigStore = configstore.NewMem()
t.ControllerStore = jujuclienttesting.NewMemControllerStore()
t.ControllerStore = jujuclienttesting.NewMemStore()
t.PatchValue(&simplestreams.SimplestreamsJujuPublicKey, sstesting.SignedMetadataPublicKey)
}

Expand Down Expand Up @@ -822,7 +822,7 @@ func (t *LiveTests) TestBootstrapWithDefaultSeries(c *gc.C) {
args.Config = dummyCfg
dummyenv, err := environs.Prepare(envtesting.BootstrapContext(c),
configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
dummyCfg.Name(),
args)
c.Assert(err, jc.ErrorIsNil)
Expand Down
2 changes: 1 addition & 1 deletion environs/jujutest/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (t *Tests) SetUpTest(c *gc.C) {
t.ToolsFixture.SetUpTest(c)
t.UploadFakeToolsToDirectory(c, storageDir, "released", "released")
t.ConfigStore = configstore.NewMem()
t.ControllerStore = jujuclienttesting.NewMemControllerStore()
t.ControllerStore = jujuclienttesting.NewMemStore()
}

func (t *Tests) TearDownTest(c *gc.C) {
Expand Down
16 changes: 8 additions & 8 deletions environs/open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (s *OpenSuite) TestNewDummyEnviron(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummySampleConfig())
c.Assert(err, jc.ErrorIsNil)
ctx := envtesting.BootstrapContext(c)
cache := jujuclienttesting.NewMemControllerStore()
cache := jujuclienttesting.NewMemStore()
env, err := environs.Prepare(ctx, configstore.NewMem(), cache, cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
c.Assert(err, jc.ErrorIsNil)

Expand All @@ -72,7 +72,7 @@ func (s *OpenSuite) TestNewDummyEnviron(c *gc.C) {

func (s *OpenSuite) TestUpdateEnvInfo(c *gc.C) {
store := configstore.NewMem()
cache := jujuclienttesting.NewMemControllerStore()
cache := jujuclienttesting.NewMemStore()
ctx := envtesting.BootstrapContext(c)
cfg, err := config.New(config.UseDefaults, map[string]interface{}{
"type": "dummy",
Expand Down Expand Up @@ -133,7 +133,7 @@ func (*OpenSuite) TestPrepare(c *gc.C) {
cfg, err := config.New(config.NoDefaults, baselineAttrs)
c.Assert(err, jc.ErrorIsNil)
store := configstore.NewMem()
controllerStore := jujuclienttesting.NewMemControllerStore()
controllerStore := jujuclienttesting.NewMemStore()
ctx := envtesting.BootstrapContext(c)
env, err := environs.Prepare(ctx, store, controllerStore, cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
c.Assert(err, jc.ErrorIsNil)
Expand Down Expand Up @@ -188,13 +188,13 @@ func (*OpenSuite) TestPrepareGeneratesDifferentAdminSecrets(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)

ctx := envtesting.BootstrapContext(c)
env0, err := environs.Prepare(ctx, configstore.NewMem(), jujuclienttesting.NewMemControllerStore(), cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
env0, err := environs.Prepare(ctx, configstore.NewMem(), jujuclienttesting.NewMemStore(), cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
c.Assert(err, jc.ErrorIsNil)
adminSecret0 := env0.Config().AdminSecret()
c.Assert(adminSecret0, gc.HasLen, 32)
c.Assert(adminSecret0, gc.Matches, "^[0-9a-f]*$")

env1, err := environs.Prepare(ctx, configstore.NewMem(), jujuclienttesting.NewMemControllerStore(), cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
env1, err := environs.Prepare(ctx, configstore.NewMem(), jujuclienttesting.NewMemStore(), cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
c.Assert(err, jc.ErrorIsNil)
adminSecret1 := env1.Config().AdminSecret()
c.Assert(adminSecret1, gc.HasLen, 32)
Expand All @@ -213,7 +213,7 @@ func (*OpenSuite) TestPrepareWithMissingKey(c *gc.C) {
))
c.Assert(err, jc.ErrorIsNil)
store := configstore.NewMem()
controllerStore := jujuclienttesting.NewMemControllerStore()
controllerStore := jujuclienttesting.NewMemStore()
env, err := environs.Prepare(envtesting.BootstrapContext(c), store, controllerStore, cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
c.Assert(err, gc.ErrorMatches, "cannot ensure CA certificate: controller configuration with a certificate but no CA private key")
c.Assert(env, gc.IsNil)
Expand All @@ -233,7 +233,7 @@ func (*OpenSuite) TestPrepareWithExistingKeyPair(c *gc.C) {
))
c.Assert(err, jc.ErrorIsNil)
ctx := envtesting.BootstrapContext(c)
env, err := environs.Prepare(ctx, configstore.NewMem(), jujuclienttesting.NewMemControllerStore(), cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
env, err := environs.Prepare(ctx, configstore.NewMem(), jujuclienttesting.NewMemStore(), cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
c.Assert(err, jc.ErrorIsNil)
cfgCertPEM, cfgCertOK := env.Config().CACert()
cfgKeyPEM, cfgKeyOK := env.Config().CAPrivateKey()
Expand All @@ -253,7 +253,7 @@ func (*OpenSuite) TestDestroy(c *gc.C) {
c.Assert(err, jc.ErrorIsNil)

store := configstore.NewMem()
controllerStore := jujuclienttesting.NewMemControllerStore()
controllerStore := jujuclienttesting.NewMemStore()
// Prepare the environment and sanity-check that
// the config storage info has been made.
ctx := envtesting.BootstrapContext(c)
Expand Down
2 changes: 1 addition & 1 deletion environs/tools/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *SimpleStreamsToolsSuite) resetEnv(c *gc.C, attrs map[string]interface{}
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig().Merge(attrs))
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(envtesting.BootstrapContext(c), configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
c.Assert(err, jc.ErrorIsNil)
s.env = env
Expand Down
2 changes: 1 addition & 1 deletion environs/tools/urls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (s *URLsSuite) env(c *gc.C, toolsMetadataURL string) environs.Environ {
cfg, err := config.New(config.NoDefaults, attrs)
c.Assert(err, jc.ErrorIsNil)
env, err := environs.Prepare(envtesting.BootstrapContext(c), configstore.NewMem(),
jujuclienttesting.NewMemControllerStore(),
jujuclienttesting.NewMemStore(),
cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
c.Assert(err, jc.ErrorIsNil)
return env
Expand Down
24 changes: 12 additions & 12 deletions juju/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (cs *NewAPIStateSuite) TestNewAPIState(c *gc.C) {
cfg, err := config.New(config.NoDefaults, dummy.SampleConfig())
c.Assert(err, jc.ErrorIsNil)
ctx := envtesting.BootstrapContext(c)
cache := jujuclienttesting.NewMemControllerStore()
cache := jujuclienttesting.NewMemStore()
env, err := environs.Prepare(ctx, configstore.NewMem(), cache, cfg.Name(), environs.PrepareForBootstrapParams{Config: cfg})
c.Assert(err, jc.ErrorIsNil)

Expand Down Expand Up @@ -165,7 +165,7 @@ func (s *NewAPIClientSuite) bootstrapEnv(c *gc.C, store configstore.Storage, con
store = configstore.NewMem()
}
if controllerStore == nil {
controllerStore = jujuclienttesting.NewMemControllerStore()
controllerStore = jujuclienttesting.NewMemStore()
}

ctx := envtesting.BootstrapContext(c)
Expand Down Expand Up @@ -247,7 +247,7 @@ func (s *NewAPIClientSuite) TestWithInfoOnly(c *gc.C) {
func (s *NewAPIClientSuite) TestWithInfoError(c *gc.C) {
expectErr := fmt.Errorf("an error")
store := newConfigStoreWithError(expectErr)
client, err := juju.NewAPIFromStore("noconfig", store, jujuclienttesting.NewMemControllerStore(), panicAPIOpen)
client, err := juju.NewAPIFromStore("noconfig", store, jujuclienttesting.NewMemStore(), panicAPIOpen)
c.Assert(errors.Cause(err), gc.Equals, expectErr)
c.Assert(client, gc.IsNil)
}
Expand Down Expand Up @@ -346,7 +346,7 @@ func (s *NewAPIClientSuite) TestWithInfoNoModelTag(c *gc.C) {
// Give NewAPIFromStore a store interface that can report when the
// config was written to, to check if the cache is updated.
mockStore := &storageWithWriteNotify{store: store}
jujuclient := jujuclienttesting.NewMemControllerStore()
jujuclient := jujuclienttesting.NewMemStore()
st, err := juju.NewAPIFromStore("noconfig", mockStore, jujuclient, apiOpen)
c.Assert(err, jc.ErrorIsNil)
c.Assert(st, gc.Equals, expectState)
Expand Down Expand Up @@ -395,7 +395,7 @@ func (s *NewAPIClientSuite) TestWithInfoNoAPIHostports(c *gc.C) {
}

mockStore := &storageWithWriteNotify{store: store}
st, err := juju.NewAPIFromStore("noconfig", mockStore, jujuclienttesting.NewMemControllerStore(), apiOpen)
st, err := juju.NewAPIFromStore("noconfig", mockStore, jujuclienttesting.NewMemStore(), apiOpen)
c.Assert(err, jc.ErrorIsNil)
c.Assert(st, gc.Equals, expectState)
c.Assert(called, gc.Equals, 1)
Expand Down Expand Up @@ -424,7 +424,7 @@ func (s *NewAPIClientSuite) TestNoModelTagDoesntOverwriteCached(c *gc.C) {
}

mockStore := &storageWithWriteNotify{store: store}
controllerStore := jujuclienttesting.NewMemControllerStore()
controllerStore := jujuclienttesting.NewMemStore()
st, err := juju.NewAPIFromStore("noconfig", mockStore, controllerStore, apiOpen)
c.Assert(err, jc.ErrorIsNil)
c.Assert(st, gc.Equals, expectState)
Expand Down Expand Up @@ -484,7 +484,7 @@ func (s *NewAPIClientSuite) TestWithInfoAPIOpenError(c *gc.C) {
func (s *NewAPIClientSuite) TestWithSlowInfoConnect(c *gc.C) {
s.PatchValue(&version.Current, coretesting.FakeVersionNumber)
store := configstore.NewMem()
controllerStore := jujuclienttesting.NewMemControllerStore()
controllerStore := jujuclienttesting.NewMemStore()
s.bootstrapEnv(c, store, controllerStore)
setEndpointAddressAndHostname(c, store, "0.1.2.3", "infoapi.invalid")

Expand Down Expand Up @@ -571,7 +571,7 @@ func (s *NewAPIClientSuite) TestWithSlowConfigConnect(c *gc.C) {
s.PatchValue(&version.Current, coretesting.FakeVersionNumber)

store := configstore.NewMem()
controllerStore := jujuclienttesting.NewMemControllerStore()
controllerStore := jujuclienttesting.NewMemStore()
s.bootstrapEnv(c, store, controllerStore)
setEndpointAddressAndHostname(c, store, "0.1.2.3", "infoapi.invalid")

Expand Down Expand Up @@ -641,7 +641,7 @@ func (s *NewAPIClientSuite) TestWithSlowConfigConnect(c *gc.C) {
func (s *NewAPIClientSuite) TestBothError(c *gc.C) {
s.PatchValue(&version.Current, coretesting.FakeVersionNumber)
store := configstore.NewMem()
controllerStore := jujuclienttesting.NewMemControllerStore()
controllerStore := jujuclienttesting.NewMemStore()
s.bootstrapEnv(c, store, controllerStore)
setEndpointAddressAndHostname(c, store, "0.1.2.3", "infoapi.invalid")

Expand All @@ -666,7 +666,7 @@ func defaultConfigStore(c *gc.C) configstore.Storage {
func (s *NewAPIClientSuite) TestWithBootstrapConfigAndNoEnvironmentsFile(c *gc.C) {
s.PatchValue(&version.Current, coretesting.FakeVersionNumber)
store := configstore.NewMem()
controllerStore := jujuclienttesting.NewMemControllerStore()
controllerStore := jujuclienttesting.NewMemStore()
s.bootstrapEnv(c, store, controllerStore)
info, err := store.ReadInfo("my-controller")
c.Assert(err, jc.ErrorIsNil)
Expand Down Expand Up @@ -729,7 +729,7 @@ func newConfigStore(envName string, info *environInfo) configstore.Storage {
// newControllerStore returns controller store that contains information
// for the controller name.
func newControllerStore(controllerName string, info *environInfo) jujuclient.ControllerStore {
controllerStore := jujuclienttesting.NewMemControllerStore()
controllerStore := jujuclienttesting.NewMemStore()

err := controllerStore.UpdateController(controllerName, jujuclient.ControllerDetails{
info.endpoint.Hostnames,
Expand Down Expand Up @@ -834,7 +834,7 @@ func (s *CacheAPIEndpointsSuite) SetUpTest(c *gc.C) {
s.numResolved = 0
s.modelTag = names.NewModelTag(fakeUUID)
s.store = configstore.NewMem()
s.controllerStore = jujuclienttesting.NewMemControllerStore()
s.controllerStore = jujuclienttesting.NewMemStore()

s.JujuConnSuite.SetUpTest(c)

Expand Down
Loading

0 comments on commit 5686c67

Please sign in to comment.