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

Delta Between Two Patch Sets: cmd/juju/synctools_test.go

Issue 8545043: environs: extract tools package
Left Patch Set: Created 10 years, 11 months ago
Right Patch Set: environs: extract tools package Created 10 years, 11 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:
Right: Side by side diff | Download
« no previous file with change/comment | « cmd/juju/synctools.go ('k') | cmd/juju/upgradejuju.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 package main 1 package main
2 2
3 import ( 3 import (
4 "bytes"
5 "io/ioutil" 4 "io/ioutil"
6 . "launchpad.net/gocheck" 5 . "launchpad.net/gocheck"
7 "launchpad.net/juju-core/cmd" 6 "launchpad.net/juju-core/cmd"
8 "launchpad.net/juju-core/environs" 7 "launchpad.net/juju-core/environs"
9 "launchpad.net/juju-core/environs/dummy" 8 "launchpad.net/juju-core/environs/dummy"
9 envtesting "launchpad.net/juju-core/environs/testing"
10 "launchpad.net/juju-core/state" 10 "launchpad.net/juju-core/state"
11 "launchpad.net/juju-core/testing" 11 "launchpad.net/juju-core/testing"
12 "launchpad.net/juju-core/version" 12 "launchpad.net/juju-core/version"
13 "os" 13 "os"
14 "sort" 14 "sort"
15 ) 15 )
16 16
17 type syncToolsSuite struct { 17 type syncToolsSuite struct {
18 testing.LoggingSuite 18 testing.LoggingSuite
19 home *testing.FakeHome 19 home *testing.FakeHome
(...skipping 15 matching lines...) Expand all
35 func runSyncToolsCommand(c *C, args ...string) (*cmd.Context, error) { 35 func runSyncToolsCommand(c *C, args ...string) (*cmd.Context, error) {
36 return testing.RunCommand(c, &SyncToolsCommand{}, args) 36 return testing.RunCommand(c, &SyncToolsCommand{}, args)
37 } 37 }
38 38
39 func (s *syncToolsSuite) TestHelp(c *C) { 39 func (s *syncToolsSuite) TestHelp(c *C) {
40 ctx, err := runSyncToolsCommand(c, "-h") 40 ctx, err := runSyncToolsCommand(c, "-h")
41 c.Assert(err, ErrorMatches, "flag: help requested") 41 c.Assert(err, ErrorMatches, "flag: help requested")
42 c.Assert(ctx, IsNil) 42 c.Assert(ctx, IsNil)
43 } 43 }
44 44
45 func uploadDummyTools(c *C, vers version.Binary, store environs.Storage) { 45 func uploadDummyTools(c *C, vers version.Binary, storage environs.Storage) {
46 » path := environs.ToolsStoragePath(vers) 46 » envtesting.UploadFakeToolsVersion(c, storage, vers)
47 » content := bytes.NewBufferString("content\n")
48 » err := store.Put(path, content, int64(content.Len()))
49 » c.Assert(err, IsNil)
50 }
51
52 func deletePublicTools(c *C, store environs.Storage) {
53 » // Dummy environments always put fake tools, but we don't want it
54 » // confusing our state, so we delete them
55 » dummyTools, err := store.List("tools/juju")
56 » c.Assert(err, IsNil)
57 » for _, path := range dummyTools {
58 » » err = store.Remove(path)
59 » » c.Assert(err, IsNil)
60 » }
61 } 47 }
62 48
63 func setupDummyEnvironments(c *C) (env environs.Environ, cleanup func()) { 49 func setupDummyEnvironments(c *C) (env environs.Environ, cleanup func()) {
64 dummyAttrs := map[string]interface{}{ 50 dummyAttrs := map[string]interface{}{
65 "name": "test-source", 51 "name": "test-source",
66 "type": "dummy", 52 "type": "dummy",
67 "state-server": false, 53 "state-server": false,
68 // Note: Without this, you get "no public ssh keys found", which seems 54 // Note: Without this, you get "no public ssh keys found", which seems
69 // a bit odd for the "dummy" environment 55 // a bit odd for the "dummy" environment
70 "authorized-keys": "I-am-not-a-real-key", 56 "authorized-keys": "I-am-not-a-real-key",
71 } 57 }
72 env, err := environs.NewFromAttrs(dummyAttrs) 58 env, err := environs.NewFromAttrs(dummyAttrs)
73 c.Assert(err, IsNil) 59 c.Assert(err, IsNil)
74 c.Assert(env, NotNil) 60 c.Assert(env, NotNil)
75 store := env.PublicStorage().(environs.Storage) 61 store := env.PublicStorage().(environs.Storage)
76 » deletePublicTools(c, store) 62 » envtesting.RemoveTools(c, store)
77 // Upload multiple tools 63 // Upload multiple tools
78 uploadDummyTools(c, t1000precise.Binary, store) 64 uploadDummyTools(c, t1000precise.Binary, store)
79 uploadDummyTools(c, t1000quantal.Binary, store) 65 uploadDummyTools(c, t1000quantal.Binary, store)
80 uploadDummyTools(c, t1000quantal32.Binary, store) 66 uploadDummyTools(c, t1000quantal32.Binary, store)
81 uploadDummyTools(c, t1900quantal.Binary, store) 67 uploadDummyTools(c, t1900quantal.Binary, store)
82 // Overwrite the official source bucket to the new dummy 'test-source', 68 // Overwrite the official source bucket to the new dummy 'test-source',
83 // saving the original value for cleanup 69 // saving the original value for cleanup
84 orig := officialBucketAttrs 70 orig := officialBucketAttrs
85 officialBucketAttrs = dummyAttrs 71 officialBucketAttrs = dummyAttrs
86 // Create a target dummy environment 72 // Create a target dummy environment
(...skipping 25 matching lines...) Expand all
112 if expected == nil { 98 if expected == nil {
113 expected = []string{} 99 expected = []string{}
114 } 100 }
115 c.Assert(actual, DeepEquals, expected) 101 c.Assert(actual, DeepEquals, expected)
116 } 102 }
117 103
118 func setupTargetEnv(c *C) environs.Environ { 104 func setupTargetEnv(c *C) environs.Environ {
119 targetEnv, err := environs.NewFromName("test-target") 105 targetEnv, err := environs.NewFromName("test-target")
120 c.Assert(err, IsNil) 106 c.Assert(err, IsNil)
121 store := targetEnv.PublicStorage().(environs.Storage) 107 store := targetEnv.PublicStorage().(environs.Storage)
122 » deletePublicTools(c, store) 108 » envtesting.RemoveTools(c, store)
123 » targetTools, err := environs.ListTools(targetEnv, 1) 109 » toolsList, err := environs.ListTools(targetEnv, 1)
124 » // Target has no tools. 110 » c.Assert(err, IsNil)
125 » c.Assert(targetTools.Public, HasLen, 0) 111 » c.Assert(toolsList.Private, HasLen, 0)
126 » c.Assert(targetTools.Private, HasLen, 0) 112 » c.Assert(toolsList.Public, HasLen, 0)
127 return targetEnv 113 return targetEnv
128 } 114 }
129 115
130 func (s *syncToolsSuite) TestCopyNewestFromDummy(c *C) { 116 func (s *syncToolsSuite) TestCopyNewestFromDummy(c *C) {
131 sourceEnv, cleanup := setupDummyEnvironments(c) 117 sourceEnv, cleanup := setupDummyEnvironments(c)
132 defer cleanup() 118 defer cleanup()
133 sourceTools, err := environs.ListTools(sourceEnv, 1) 119 sourceTools, err := environs.ListTools(sourceEnv, 1)
134 c.Assert(err, IsNil) 120 c.Assert(err, IsNil)
135 assertToolsList(c, sourceTools.Public, 121 assertToolsList(c, sourceTools.Public,
136 "1.0.0-precise-amd64", "1.0.0-quantal-amd64", 122 "1.0.0-precise-amd64", "1.0.0-quantal-amd64",
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 "1.0.0-quantal-i386", "1.9.0-quantal-amd64") 171 "1.0.0-quantal-i386", "1.9.0-quantal-amd64")
186 c.Assert(sourceTools.Private, HasLen, 0) 172 c.Assert(sourceTools.Private, HasLen, 0)
187 173
188 targetEnv := setupTargetEnv(c) 174 targetEnv := setupTargetEnv(c)
189 175
190 ctx, err := runSyncToolsCommand(c, "-e", "test-target", "--public") 176 ctx, err := runSyncToolsCommand(c, "-e", "test-target", "--public")
191 c.Assert(err, IsNil) 177 c.Assert(err, IsNil)
192 c.Assert(ctx, NotNil) 178 c.Assert(ctx, NotNil)
193 targetTools, err := environs.ListTools(targetEnv, 1) 179 targetTools, err := environs.ListTools(targetEnv, 1)
194 c.Assert(err, IsNil) 180 c.Assert(err, IsNil)
195 » // newest tools added to the private bucket 181 » // newest tools added to the public bucket
196 assertToolsList(c, targetTools.Public, "1.9.0-quantal-amd64") 182 assertToolsList(c, targetTools.Public, "1.9.0-quantal-amd64")
197 c.Assert(targetTools.Private, HasLen, 0) 183 c.Assert(targetTools.Private, HasLen, 0)
198 } 184 }
199 185
200 func mustParseTools(major, minor, patch, build int, series string, arch string) *state.Tools { 186 func mustParseTools(major, minor, patch, build int, series string, arch string) *state.Tools {
201 return &state.Tools{ 187 return &state.Tools{
202 Binary: version.Binary{ 188 Binary: version.Binary{
203 Number: version.Number{major, minor, patch, build}, 189 Number: version.Number{major, minor, patch, build},
204 Series: series, 190 Series: series,
205 Arch: arch}} 191 Arch: arch}}
206 } 192 }
207 193
208 var ( 194 var (
209 t1000precise = mustParseTools(1, 0, 0, 0, "precise", "amd64") 195 t1000precise = mustParseTools(1, 0, 0, 0, "precise", "amd64")
210 t1000quantal = mustParseTools(1, 0, 0, 0, "quantal", "amd64") 196 t1000quantal = mustParseTools(1, 0, 0, 0, "quantal", "amd64")
211 t1000quantal32 = mustParseTools(1, 0, 0, 0, "quantal", "i386") 197 t1000quantal32 = mustParseTools(1, 0, 0, 0, "quantal", "i386")
212 t1900quantal = mustParseTools(1, 9, 0, 0, "quantal", "amd64") 198 t1900quantal = mustParseTools(1, 9, 0, 0, "quantal", "amd64")
213 t2000precise = mustParseTools(2, 0, 0, 0, "precise", "amd64") 199 t2000precise = mustParseTools(2, 0, 0, 0, "precise", "amd64")
214 ) 200 )
LEFTRIGHT

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