Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1618)

Side by Side Diff: environs/configstore/interface_test.go

Issue 13489044: environs/configstore: memory-based store
Patch Set: environs/configstore: memory-based store Created 11 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « environs/configstore/disk_test.go ('k') | environs/configstore/mem.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 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details.
3
4 package configstore_test
5
6 import (
7 gc "launchpad.net/gocheck"
8
9 "launchpad.net/juju-core/environs"
10 jc "launchpad.net/juju-core/testing/checkers"
11 )
12
13 // interfaceSuite defines a set of tests on a ConfigStorage
14 // implementation, independent of the implementation itself.
15 // The NewStore field must be set up to return a ConfigStorage
16 // instance of the type to be tested.
17 type interfaceSuite struct {
18 NewStore func(c *gc.C) environs.ConfigStorage
19 }
20
21 func (s *interfaceSuite) TestCreate(c *gc.C) {
22 store := s.NewStore(c)
23 info, err := store.CreateInfo("someenv")
24 c.Assert(err, gc.IsNil)
25 c.Assert(info.APIEndpoint(), gc.DeepEquals, environs.APIEndpoint{})
26 c.Assert(info.APICredentials(), gc.DeepEquals, environs.APICredentials{} )
27 c.Assert(info.Initialized(), jc.IsFalse)
28
29 // Check that we can't create it twice.
30 info, err = store.CreateInfo("someenv")
31 c.Assert(err, gc.Equals, environs.ErrEnvironInfoAlreadyExists)
32 c.Assert(info, gc.IsNil)
33
34 // Check that we can read it again.
35 info, err = store.ReadInfo("someenv")
36 c.Assert(err, gc.IsNil)
37 c.Assert(info.Initialized(), jc.IsFalse)
38 }
39
40 func (s *interfaceSuite) TestSetAPIEndpointAndCredentials(c *gc.C) {
41 store := s.NewStore(c)
42
43 info, err := store.CreateInfo("someenv")
44 c.Assert(err, gc.IsNil)
45
46 expectEndpoint := environs.APIEndpoint{
47 Addresses: []string{"example.com"},
48 CACert: "a cert",
49 }
50 info.SetAPIEndpoint(expectEndpoint)
51 c.Assert(info.APIEndpoint(), gc.DeepEquals, expectEndpoint)
52
53 expectCreds := environs.APICredentials{
54 User: "foobie",
55 Password: "bletch",
56 }
57 info.SetAPICredentials(expectCreds)
58 c.Assert(info.APICredentials(), gc.DeepEquals, expectCreds)
59 }
60
61 func (s *interfaceSuite) TestWrite(c *gc.C) {
62 store := s.NewStore(c)
63
64 // Create the info.
65 info, err := store.CreateInfo("someenv")
66 c.Assert(err, gc.IsNil)
67
68 // Set it up with some actual data and write it out.
69 expectCreds := environs.APICredentials{
70 User: "foobie",
71 Password: "bletch",
72 }
73 info.SetAPICredentials(expectCreds)
74
75 expectEndpoint := environs.APIEndpoint{
76 Addresses: []string{"example.com"},
77 CACert: "a cert",
78 }
79 info.SetAPIEndpoint(expectEndpoint)
80
81 err = info.Write()
82 c.Assert(err, gc.IsNil)
83 c.Assert(info.Initialized(), jc.IsTrue)
84
85 // Check we can read the information back
86 info, err = store.ReadInfo("someenv")
87 c.Assert(err, gc.IsNil)
88 c.Assert(info.APICredentials(), gc.DeepEquals, expectCreds)
89 c.Assert(info.APIEndpoint(), gc.DeepEquals, expectEndpoint)
90
91 // Change the information and write it again.
92 expectCreds.User = "arble"
93 info.SetAPICredentials(expectCreds)
94 err = info.Write()
95 c.Assert(err, gc.IsNil)
96
97 // Check we can read the information back
98 info, err = store.ReadInfo("someenv")
99 c.Assert(err, gc.IsNil)
100 c.Assert(info.APICredentials(), gc.DeepEquals, expectCreds)
101 }
102
103 func (s *interfaceSuite) TestDestroy(c *gc.C) {
104 store := s.NewStore(c)
105
106 info, err := store.CreateInfo("someenv")
107 c.Assert(err, gc.IsNil)
108
109 err = info.Destroy()
110 c.Assert(err, gc.IsNil)
111
112 err = info.Destroy()
113 c.Assert(err, gc.ErrorMatches, "environment info has already been remove d")
114
115 info, err = store.CreateInfo("someenv")
116 c.Assert(err, gc.IsNil)
117 }
118
119 func (s *interfaceSuite) TestNoBleedThrough(c *gc.C) {
120 store := s.NewStore(c)
121
122 info, err := store.CreateInfo("someenv")
123 c.Assert(err, gc.IsNil)
124
125 info.SetAPICredentials(environs.APICredentials{User: "foo"})
126 info.SetAPIEndpoint(environs.APIEndpoint{CACert: "blah"})
127
128 info1, err := store.ReadInfo("someenv")
129 c.Assert(err, gc.IsNil)
130 c.Assert(info1.Initialized(), jc.IsFalse)
131 c.Assert(info1.APICredentials(), gc.DeepEquals, environs.APICredentials{ })
132 c.Assert(info1.APIEndpoint(), gc.DeepEquals, environs.APIEndpoint{})
133 }
OLDNEW
« no previous file with comments | « environs/configstore/disk_test.go ('k') | environs/configstore/mem.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b