Merge lp:~free.ekanayaka/fake-juju/initial-unit-tests into lp:~landscape/fake-juju/trunk-old
- initial-unit-tests
- Merge into trunk-old
Status: | Merged |
---|---|
Approved by: | Free Ekanayaka |
Approved revision: | 65 |
Merged at revision: | 60 |
Proposed branch: | lp:~free.ekanayaka/fake-juju/initial-unit-tests |
Merge into: | lp:~landscape/fake-juju/trunk-old |
Diff against target: |
555 lines (+487/-1) 11 files modified
2.0.2/Makefile (+5/-0) 2.0.2/fake-juju.go (+12/-0) 2.0.2/juju-core.patch (+101/-0) Makefile (+1/-1) common/makefile.mk (+4/-0) common/service/logging.go (+20/-0) common/service/run.go (+84/-0) common/service/run_test.go (+46/-0) common/service/service.go (+101/-0) common/service/service_test.go (+67/-0) common/service/suite.go (+46/-0) |
To merge this branch: | bzr merge lp:~free.ekanayaka/fake-juju/initial-unit-tests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Francis Ginther (community) | Approve | ||
🤖 Landscape Builder | test results | Approve | |
Review via email: mp+312046@code.launchpad.net |
Commit message
Description of the change
This branch is the first of a series that will refactor the fake-juju Go code to make it more understandable, maintainable and testable.
As first step, I've added initial 2.0.2 support (not yet fully working) and re-organized a bit of the existing fake-juju.go code into unit-tested modules, which you can find under common/service.
The idea is that each individual version-specific directory will only override what needs to change for that specific version, and code under common/ will be shared.
You can run the unit tests with:
make -C 2.0.2 unit-test
and build/run this WIP fake-juju with:
make -C 2.0.2 build
./2.0.2/2.0.2
You'll see some output and then the process will exit. More behavior will come.
🤖 Landscape Builder (landscape-builder) : | # |
- 61. By Free Ekanayaka
-
Skip regular tests
🤖 Landscape Builder (landscape-builder) wrote : | # |
🤖 Landscape Builder (landscape-builder) : | # |
- 62. By Free Ekanayaka
-
Add missing import
🤖 Landscape Builder (landscape-builder) wrote : | # |
Command: make ci-test
Result: Fail
Revno: 61
Branch: lp:~free.ekanayaka/fake-juju/initial-unit-tests
Jenkins: https:/
🤖 Landscape Builder (landscape-builder) : | # |
🤖 Landscape Builder (landscape-builder) wrote : | # |
Command: make ci-test
Result: Success
Revno: 62
Branch: lp:~free.ekanayaka/fake-juju/initial-unit-tests
Jenkins: https:/
- 63. By Free Ekanayaka
-
Rename FakeJujuState to FakeJujuService
🤖 Landscape Builder (landscape-builder) : | # |
🤖 Landscape Builder (landscape-builder) wrote : | # |
Command: make ci-test
Result: Success
Revno: 63
Branch: lp:~free.ekanayaka/fake-juju/initial-unit-tests
Jenkins: https:/
- 64. By Free Ekanayaka
-
Don't let LoggingSuite reset logging
🤖 Landscape Builder (landscape-builder) : | # |
🤖 Landscape Builder (landscape-builder) wrote : | # |
Command: make ci-test
Result: Fail
Revno: 64
Branch: lp:~free.ekanayaka/fake-juju/initial-unit-tests
Jenkins: https:/
- 65. By Free Ekanayaka
-
Fix patch file
🤖 Landscape Builder (landscape-builder) : | # |
🤖 Landscape Builder (landscape-builder) wrote : | # |
Command: make ci-test
Result: Success
Revno: 65
Branch: lp:~free.ekanayaka/fake-juju/initial-unit-tests
Jenkins: https:/
Francis Ginther (fginther) wrote : | # |
Compared this with the existing 2.0.0 version and the refactoring so far appears reasonable. As stated, much is still missing, but the refactoring approach is cleaner and more readable. And yay unit-tests!
Someone with more experience working on fake-juju may find a few things to comment on, but this looks good from my perspective.
Preview Diff
1 | === added directory '2.0.2' |
2 | === added file '2.0.2/Makefile' |
3 | --- 2.0.2/Makefile 1970-01-01 00:00:00 +0000 |
4 | +++ 2.0.2/Makefile 2016-11-30 06:28:02 +0000 |
5 | @@ -0,0 +1,5 @@ |
6 | +include ../common/makefile.mk |
7 | + |
8 | +# XXX Functionality is not complete yet |
9 | +test: |
10 | + echo "Skip, fake-juju 2.0.2 is WIP" |
11 | |
12 | === added file '2.0.2/fake-juju.go' |
13 | --- 2.0.2/fake-juju.go 1970-01-01 00:00:00 +0000 |
14 | +++ 2.0.2/fake-juju.go 2016-11-30 06:28:02 +0000 |
15 | @@ -0,0 +1,12 @@ |
16 | +package main |
17 | + |
18 | +import ( |
19 | + "os" |
20 | + "./service" |
21 | +) |
22 | + |
23 | +func main() { |
24 | + code := 0 |
25 | + service.RunFakeJuju() |
26 | + os.Exit(code) |
27 | +} |
28 | |
29 | === added file '2.0.2/juju-core.patch' |
30 | --- 2.0.2/juju-core.patch 1970-01-01 00:00:00 +0000 |
31 | +++ 2.0.2/juju-core.patch 2016-11-30 06:28:02 +0000 |
32 | @@ -0,0 +1,101 @@ |
33 | +diff -U 3 -r --no-dereference .unpacked-clean/github.com/juju/juju/apiserver/charms.go src/github.com/juju/juju/apiserver/charms.go |
34 | +--- .unpacked-clean/github.com/juju/juju/apiserver/charms.go 2016-11-11 00:08:09.000000000 +0000 |
35 | ++++ src/github.com/juju/juju/apiserver/charms.go 2016-11-30 06:09:26.975210508 +0000 |
36 | +@@ -284,7 +284,8 @@ |
37 | + if isImporting, err := modelIsImporting(st); err != nil { |
38 | + return nil, errors.Trace(err) |
39 | + } else if !isImporting { |
40 | +- return nil, errors.New("cs charms may only be uploaded during model migration import") |
41 | ++ // fake-juju allows uploading "charmstore" charms. |
42 | ++ //return nil, errors.New("cs charms may only be uploaded during model migration import") |
43 | + } |
44 | + |
45 | + // If a revision argument is provided, it takes precedence |
46 | +diff -U 3 -r --no-dereference .unpacked-clean/github.com/juju/juju/provider/dummy/environs.go src/github.com/juju/juju/provider/dummy/environs.go |
47 | +--- .unpacked-clean/github.com/juju/juju/provider/dummy/environs.go 2016-11-11 00:08:09.000000000 +0000 |
48 | ++++ src/github.com/juju/juju/provider/dummy/environs.go 2016-11-30 06:09:26.977210528 +0000 |
49 | +@@ -643,9 +643,9 @@ |
50 | + |
51 | + // PrecheckInstance is specified in the state.Prechecker interface. |
52 | + func (*environ) PrecheckInstance(series string, cons constraints.Value, placement string) error { |
53 | +- if placement != "" && placement != "valid" { |
54 | +- return fmt.Errorf("%s placement is invalid", placement) |
55 | +- } |
56 | ++// if placement != "" && placement != "valid" { |
57 | ++// return fmt.Errorf("%s placement is invalid", placement) |
58 | ++// } |
59 | + return nil |
60 | + } |
61 | + |
62 | +diff -U 3 -r --no-dereference .unpacked-clean/github.com/juju/juju/testcharms/charm.go src/github.com/juju/juju/testcharms/charm.go |
63 | +--- .unpacked-clean/github.com/juju/juju/testcharms/charm.go 2016-11-11 00:08:09.000000000 +0000 |
64 | ++++ src/github.com/juju/juju/testcharms/charm.go 2016-11-30 06:09:26.978210538 +0000 |
65 | +@@ -17,7 +17,9 @@ |
66 | + ) |
67 | + |
68 | + // Repo provides access to the test charm repository. |
69 | +-var Repo = testing.NewRepo("charm-repo", "quantal") |
70 | ++// XXX fake-juju: avoid crashing because the charm-repo dir is not there |
71 | ++//var Repo = testing.NewRepo("charm-repo", "quantal") |
72 | ++var Repo = &testing.Repo{} |
73 | + |
74 | + // UploadCharmWithMeta pushes a new charm to the charmstore. |
75 | + // The uploaded charm takes the supplied charmURL with metadata.yaml and metrics.yaml |
76 | +diff -U 3 -r --no-dereference .unpacked-clean/github.com/juju/juju/testing/cert.go src/github.com/juju/juju/testing/cert.go |
77 | +--- .unpacked-clean/github.com/juju/juju/testing/cert.go 2016-11-11 00:08:09.000000000 +0000 |
78 | ++++ src/github.com/juju/juju/testing/cert.go 2016-11-30 06:09:26.979210548 +0000 |
79 | +@@ -52,7 +52,7 @@ |
80 | + } |
81 | + |
82 | + func mustNewCA() (string, string) { |
83 | +- cert.KeyBits = 512 |
84 | ++ cert.KeyBits = 1024 |
85 | + caCert, caKey, err := cert.NewCA("juju testing", "1234-ABCD-IS-NOT-A-REAL-UUID", time.Now().AddDate(10, 0, 0)) |
86 | + if err != nil { |
87 | + panic(err) |
88 | +@@ -61,7 +61,7 @@ |
89 | + } |
90 | + |
91 | + func mustNewServer() (string, string) { |
92 | +- cert.KeyBits = 512 |
93 | ++ cert.KeyBits = 1024 |
94 | + var hostnames []string |
95 | + srvCert, srvKey, err := cert.NewServer(CACert, CAKey, time.Now().AddDate(10, 0, 0), hostnames) |
96 | + if err != nil { |
97 | +diff -U 3 -r --no-dereference .unpacked-clean/github.com/juju/testing/log.go src/github.com/juju/testing/log.go |
98 | +--- .unpacked-clean/github.com/juju/testing/log.go 2016-11-11 00:08:46.000000000 +0000 |
99 | ++++ src/github.com/juju/testing/log.go 2016-11-30 06:09:29.817238914 +0000 |
100 | +@@ -50,6 +50,9 @@ |
101 | + } |
102 | + |
103 | + func (s *LoggingSuite) TearDownSuite(c *gc.C) { |
104 | ++ // XXX fake-juju: we don't want this suite to override our logging |
105 | ++ // setup. |
106 | ++ return |
107 | + loggo.ResetLogging() |
108 | + } |
109 | + |
110 | +@@ -66,6 +69,10 @@ |
111 | + } |
112 | + |
113 | + func (s *LoggingSuite) setUp(c *gc.C) { |
114 | ++ // XXX fake-juju: we don't want this suite to override our logging |
115 | ++ // setup. |
116 | ++ return |
117 | ++ |
118 | + loggo.ResetLogging() |
119 | + // Don't use the default writer for the test logging, which |
120 | + // means we can still get logging output from tests that |
121 | +diff -U 3 -r --no-dereference .unpacked-clean/gopkg.in/mgo.v2/bson/json.go src/gopkg.in/mgo.v2/bson/json.go |
122 | +--- .unpacked-clean/gopkg.in/mgo.v2/bson/json.go 2016-11-11 00:08:13.000000000 +0000 |
123 | ++++ src/gopkg.in/mgo.v2/bson/json.go 2016-11-30 06:09:26.979210548 +0000 |
124 | +@@ -317,7 +317,8 @@ |
125 | + func jencInt(v interface{}) ([]byte, error) { |
126 | + n := v.(int) |
127 | + f := `{"$numberLong":"%d"}` |
128 | +- if n <= 1<<53 { |
129 | ++ // fake-juju apply https://github.com/go-mgo/mgo/pull/311 |
130 | ++ if int64(n) <= 1<<53 { |
131 | + f = `%d` |
132 | + } |
133 | + return fbytes(f, n), nil |
134 | |
135 | === added symlink '2.0.2/service' |
136 | === target is u'../common/service/' |
137 | === modified file 'Makefile' |
138 | --- Makefile 2016-11-28 12:56:08 +0000 |
139 | +++ Makefile 2016-11-30 06:28:02 +0000 |
140 | @@ -1,4 +1,4 @@ |
141 | -JUJU_VERSIONS = 1.25.6 2.0.0 |
142 | +JUJU_VERSIONS = 1.25.6 2.0.0 2.0.2 |
143 | |
144 | JUJUCLIENT_DOWNLOADS = $(shell pwd)/tests/jujuclient-archive |
145 | JUJUCLIENT_REQ = $(JUJUCLIENT_DOWNLOADS)/requirements |
146 | |
147 | === modified file 'common/makefile.mk' |
148 | --- common/makefile.mk 2016-11-28 14:10:57 +0000 |
149 | +++ common/makefile.mk 2016-11-30 06:28:02 +0000 |
150 | @@ -26,6 +26,10 @@ |
151 | patch -p0 < $(JUJU_PATCH) |
152 | GOPATH=$(GO_PATH) PATH=$(PATH) go build |
153 | |
154 | +.PHONY: unit-test |
155 | +unit-test: $(JUJU_TARBALL) $(JUJU_PATCH) |
156 | + GOPATH=$(GO_PATH) go test ./service -gocheck.v |
157 | + |
158 | .PHONY: test |
159 | test: $(JUJU_VERSION) |
160 | cd .. && JUJU_VERSION=$(JUJU_VERSION) python3 -m unittest tests.test_fake |
161 | |
162 | === added directory 'common/service' |
163 | === added file 'common/service/logging.go' |
164 | --- common/service/logging.go 1970-01-01 00:00:00 +0000 |
165 | +++ common/service/logging.go 2016-11-30 06:28:02 +0000 |
166 | @@ -0,0 +1,20 @@ |
167 | +// Logging configuration |
168 | + |
169 | +package service |
170 | + |
171 | +import ( |
172 | + "io" |
173 | + "github.com/juju/loggo" |
174 | +) |
175 | + |
176 | +var ( |
177 | + log = loggo.GetLogger("") |
178 | +) |
179 | + |
180 | +func setupLogging(output io.Writer, level loggo.Level) { |
181 | + |
182 | + loggo.ResetWriters() |
183 | + loggo.RegisterWriter("default", loggo.NewColorWriter(output)) |
184 | + |
185 | + log.SetLogLevel(level) |
186 | +} |
187 | |
188 | === added file 'common/service/run.go' |
189 | --- common/service/run.go 1970-01-01 00:00:00 +0000 |
190 | +++ common/service/run.go 2016-11-30 06:28:02 +0000 |
191 | @@ -0,0 +1,84 @@ |
192 | +// Run the fake-juju service |
193 | + |
194 | +package service |
195 | + |
196 | +import ( |
197 | + "io/ioutil" |
198 | + "os" |
199 | + |
200 | + gc "gopkg.in/check.v1" |
201 | + |
202 | + "github.com/juju/loggo" |
203 | + |
204 | + coretesting "github.com/juju/juju/testing" |
205 | + jujutesting "github.com/juju/testing" |
206 | +) |
207 | + |
208 | +// Main entry point for running the fake-juju service. It will create |
209 | +// a FakeJujuSuite instance (yes, a gocheck test suite, see its docstring) |
210 | +// and run it (i.e. invoke its single TestStart test method, which will |
211 | +// spin a FakeJujuService indefinitely). |
212 | +func RunFakeJuju() { |
213 | + |
214 | + series := "xenial" |
215 | + if os.Getenv("DEFAULT_SERIES") != "" { |
216 | + series = os.Getenv("DEFAULT_SERIES") |
217 | + } |
218 | + |
219 | + options := &FakeJujuOptions{ |
220 | + Output: os.Stdout, |
221 | + Level: loggo.INFO, |
222 | + Series: series, |
223 | + Mongo: true, |
224 | + } |
225 | + suite := &FakeJujuSuite{ |
226 | + options: options, |
227 | + } |
228 | + runner := NewFakeJujuRunner(suite, options) |
229 | + runner.Run() |
230 | +} |
231 | + |
232 | +func NewFakeJujuRunner(suite interface{}, options *FakeJujuOptions) *FakeJujuRunner { |
233 | + return &FakeJujuRunner{ |
234 | + suite: suite, |
235 | + options: options, |
236 | + } |
237 | +} |
238 | + |
239 | +type FakeJujuRunner struct { |
240 | + suite interface{} // A FakeJujuSuite instance |
241 | + options *FakeJujuOptions |
242 | +} |
243 | + |
244 | +func (f *FakeJujuRunner) Run() *gc.Result { |
245 | + |
246 | + setupLogging(f.options.Output, f.options.Level) |
247 | + log.Infof("Starting service") |
248 | + |
249 | + // Conditionally start mongo (we don't want this for unit tests). |
250 | + if f.options.Mongo { |
251 | + certs := coretesting.Certs |
252 | + if err := jujutesting.MgoServer.Start(certs); err != nil { |
253 | + return &gc.Result{RunError: err} |
254 | + } |
255 | + defer jujutesting.MgoServer.Destroy() |
256 | + } |
257 | + |
258 | + conf := &gc.RunConf{ |
259 | + Output: ioutil.Discard, // We don't want any output from gocheck |
260 | + Filter: "TestStart", |
261 | + } |
262 | + result := gc.Run(f.suite, conf) |
263 | + |
264 | + if !(result.Succeeded == 1) { |
265 | + message := "No error message" |
266 | + if result.RunError != nil { |
267 | + message = result.RunError.Error() |
268 | + } |
269 | + log.Infof("Service exited uncleanly: %s", message) |
270 | + } |
271 | + log.Infof("Stopping service") |
272 | + |
273 | + return result |
274 | + |
275 | +} |
276 | |
277 | === added file 'common/service/run_test.go' |
278 | --- common/service/run_test.go 1970-01-01 00:00:00 +0000 |
279 | +++ common/service/run_test.go 2016-11-30 06:28:02 +0000 |
280 | @@ -0,0 +1,46 @@ |
281 | +package service_test |
282 | + |
283 | +import ( |
284 | + "bytes" |
285 | + |
286 | + gc "gopkg.in/check.v1" |
287 | + |
288 | + "github.com/juju/loggo" |
289 | + |
290 | + "../service" |
291 | +) |
292 | + |
293 | +type DummySuite struct { |
294 | + options *service.FakeJujuOptions |
295 | + hasRun bool |
296 | +} |
297 | + |
298 | +func (s *DummySuite) TestStart(c *gc.C) { |
299 | + s.hasRun = true |
300 | +} |
301 | + |
302 | +type FakeJujuRunnerSuite struct {} |
303 | + |
304 | +// The FakeJujuRunner.Run method executes the given gocheck suite. Logging is |
305 | +// configured too. |
306 | +func (s *FakeJujuRunnerSuite) TestRun(c *gc.C) { |
307 | + output := &bytes.Buffer{} |
308 | + options := &service.FakeJujuOptions{ |
309 | + Output: output, |
310 | + Level: loggo.DEBUG, |
311 | + Mongo: false, |
312 | + } |
313 | + suite := &DummySuite{ |
314 | + options: options, |
315 | + } |
316 | + runner := service.NewFakeJujuRunner(gc.Suite(suite), options) |
317 | + result := runner.Run() |
318 | + |
319 | + c.Assert(result.Succeeded, gc.Equals, 1) |
320 | + c.Assert(result.RunError, gc.IsNil) |
321 | + c.Assert(suite.hasRun, gc.Equals, true) |
322 | + c.Assert( |
323 | + bytes.Contains(output.Bytes(), []byte("Starting service")), gc.Equals, true) |
324 | +} |
325 | + |
326 | +var _ = gc.Suite(&FakeJujuRunnerSuite{}) |
327 | |
328 | === added file 'common/service/service.go' |
329 | --- common/service/service.go 1970-01-01 00:00:00 +0000 |
330 | +++ common/service/service.go 2016-11-30 06:28:02 +0000 |
331 | @@ -0,0 +1,101 @@ |
332 | +package service |
333 | + |
334 | +import ( |
335 | + "fmt" |
336 | + "io" |
337 | + |
338 | + "github.com/juju/juju/api" |
339 | + "github.com/juju/juju/instance" |
340 | + "github.com/juju/juju/network" |
341 | + "github.com/juju/juju/state" |
342 | + "github.com/juju/juju/version" |
343 | + "github.com/juju/loggo" |
344 | + "github.com/juju/utils" |
345 | + |
346 | + semversion "github.com/juju/version" |
347 | +) |
348 | + |
349 | +// Runtime options for the fake-juju service |
350 | +type FakeJujuOptions struct { |
351 | + Output io.Writer // Where to write logs |
352 | + Level loggo.Level // The log level |
353 | + Series string // Default Ubuntu series |
354 | + Mongo bool // Whether to start mongo, it's off for unit tests |
355 | +} |
356 | + |
357 | +// The core fake-juju service |
358 | +func NewFakeJujuService( |
359 | + state *state.State, api api.Connection, options *FakeJujuOptions) *FakeJujuService { |
360 | + |
361 | + return &FakeJujuService{ |
362 | + state: state, |
363 | + api: api, |
364 | + options: options, |
365 | + } |
366 | +} |
367 | + |
368 | +type FakeJujuService struct { |
369 | + state *state.State |
370 | + api api.Connection |
371 | + options *FakeJujuOptions |
372 | + instanceCount int |
373 | +} |
374 | + |
375 | +// Main initialization entry point |
376 | +func (s *FakeJujuService) Initialize() error { |
377 | + |
378 | + // Juju needs internet access to reach the charm store. This is |
379 | + // necessary to download charmstore charms (e.g. when adding a |
380 | + // service. In the case of downloading charms, the controller |
381 | + // does not try to download if the charm is already in the database. |
382 | + // So internet access could go back to disabled if we were to add |
383 | + // the charm directly before using any API methods that try to |
384 | + // download it. Here are some ideas on how to do that: |
385 | + // * use the API's "upload charm" HTTP endpoint (POST on /charms); |
386 | + // this requires disabling the prohibition against uploading |
387 | + // charmstore charms (which we've done already in fake-juju); |
388 | + // this could be accomplished using txjuju, python-jujuclient, |
389 | + // or manually with httplib (all have auth complexity) |
390 | + // * add an "upload-charm" command to fake-juju that forces a |
391 | + // charmstore charm into the DB |
392 | + // * add the service with a "local" charm schema and then forcibly |
393 | + // change the charm's schema to "cs" in the DB |
394 | + // In the meantime, we allow fake-juju to have internet access. |
395 | + // XXX (lp:1639276): Remove this special case. |
396 | + utils.OutgoingAccessAllowed = true |
397 | + |
398 | + ports := s.api.APIHostPorts() |
399 | + ports[0][0].SpaceName = "dummy-provider-network" |
400 | + err := s.state.SetAPIHostPorts(ports) |
401 | + if err != nil { |
402 | + return err |
403 | + } |
404 | + |
405 | + config := map[string]interface{}{"default-series": s.options.Series} |
406 | + err = s.state.UpdateModelConfig(config, nil, nil) |
407 | + if err != nil { |
408 | + return err |
409 | + } |
410 | + |
411 | + return nil |
412 | +} |
413 | + |
414 | +// Initialize the controller machine (aka machine 0). |
415 | +func (s *FakeJujuService) InitializeController(controller *state.Machine) error { |
416 | + currentVersion := version.Current.String() |
417 | + |
418 | + agentVersion, err := semversion.ParseBinary(currentVersion + "-xenial-amd64") |
419 | + if err != nil { |
420 | + return err |
421 | + } |
422 | + |
423 | + controller.SetAgentVersion(agentVersion) |
424 | + |
425 | + address := network.NewScopedAddress("127.0.0.1", network.ScopeCloudLocal) |
426 | + return controller.SetProviderAddresses(address) |
427 | +} |
428 | + |
429 | +func (s *FakeJujuService) NewInstanceId() instance.Id { |
430 | + s.instanceCount += 1 |
431 | + return instance.Id(fmt.Sprintf("id-%d", s.instanceCount)) |
432 | +} |
433 | |
434 | === added file 'common/service/service_test.go' |
435 | --- common/service/service_test.go 1970-01-01 00:00:00 +0000 |
436 | +++ common/service/service_test.go 2016-11-30 06:28:02 +0000 |
437 | @@ -0,0 +1,67 @@ |
438 | +package service_test |
439 | + |
440 | +import ( |
441 | + "testing" |
442 | + |
443 | + gc "gopkg.in/check.v1" |
444 | + |
445 | + "github.com/juju/juju/agent" |
446 | + "github.com/juju/juju/state" |
447 | + "github.com/juju/juju/testing/factory" |
448 | + "github.com/juju/juju/version" |
449 | + "github.com/juju/utils" |
450 | + |
451 | + coretesting "github.com/juju/juju/juju/testing" |
452 | + jujutesting "github.com/juju/juju/testing" |
453 | + |
454 | + "../service" |
455 | +) |
456 | + |
457 | +type FakeJujuServiceSuite struct { |
458 | + coretesting.JujuConnSuite |
459 | + service *service.FakeJujuService |
460 | +} |
461 | + |
462 | +func (s *FakeJujuServiceSuite) SetUpTest(c *gc.C) { |
463 | + s.JujuConnSuite.SetUpTest(c) |
464 | + |
465 | + options := &service.FakeJujuOptions{} |
466 | + s.service = service.NewFakeJujuService(s.State, s.APIState, options) |
467 | +} |
468 | + |
469 | +// The Initialize() method performs various initialization tasks. |
470 | +func (s *FakeJujuServiceSuite) TestInitialize(c *gc.C) { |
471 | + err := s.service.Initialize() |
472 | + c.Assert(err, gc.IsNil) |
473 | + c.Assert(utils.OutgoingAccessAllowed, gc.Equals, true) |
474 | + |
475 | + ports, err := s.State.APIHostPorts() |
476 | + c.Assert(err, gc.IsNil) |
477 | + c.Assert(string(ports[0][0].SpaceName), gc.Equals, "dummy-provider-network") |
478 | +} |
479 | + |
480 | +// The InitializeController() method configures the controller machine. |
481 | +func (s *FakeJujuServiceSuite) TestInitializeController(c *gc.C) { |
482 | + controller := s.Factory.MakeMachine(c, &factory.MachineParams{ |
483 | + InstanceId: s.service.NewInstanceId(), |
484 | + Nonce: agent.BootstrapNonce, |
485 | + Jobs: []state.MachineJob{state.JobManageModel, state.JobHostUnits}, |
486 | + Series: "xenial", |
487 | + }) |
488 | + err := s.service.InitializeController(controller) |
489 | + c.Assert(err, gc.IsNil) |
490 | + |
491 | + tools, err := controller.AgentTools() |
492 | + c.Assert(err, gc.IsNil) |
493 | + c.Assert( |
494 | + tools.Version.String(), |
495 | + gc.Equals, |
496 | + version.Current.String()+"-xenial-amd64") |
497 | +} |
498 | + |
499 | +var _ = gc.Suite(&FakeJujuServiceSuite{}) |
500 | + |
501 | +// Hook up gocheck into the "go test" runner. |
502 | +func Test(t *testing.T) { |
503 | + jujutesting.MgoTestPackage(t) |
504 | +} |
505 | |
506 | === added file 'common/service/suite.go' |
507 | --- common/service/suite.go 1970-01-01 00:00:00 +0000 |
508 | +++ common/service/suite.go 2016-11-30 06:28:02 +0000 |
509 | @@ -0,0 +1,46 @@ |
510 | +package service |
511 | + |
512 | +import ( |
513 | + gc "gopkg.in/check.v1" |
514 | + corecharm "gopkg.in/juju/charmrepo.v2-unstable" |
515 | + |
516 | + "github.com/juju/juju/agent" |
517 | + "github.com/juju/juju/juju/testing" |
518 | + "github.com/juju/juju/state" |
519 | + "github.com/juju/juju/testing/factory" |
520 | +) |
521 | + |
522 | +// Wrapper to setup and run the core FakeJujuService. |
523 | +// |
524 | +// It's implemented as a gocheck test suite because that's the easiest way |
525 | +// to re-use all the code that sets up the dummy provider. Ideally such |
526 | +// logic should be factored out from testing-related tooling and be made |
527 | +// standalone. |
528 | +type FakeJujuSuite struct { |
529 | + testing.JujuConnSuite |
530 | + |
531 | + options *FakeJujuOptions |
532 | + service *FakeJujuService |
533 | +} |
534 | + |
535 | +func (s *FakeJujuSuite) SetUpTest(c *gc.C) { |
536 | + s.JujuConnSuite.SetUpTest(c) |
537 | + |
538 | + s.PatchValue(&corecharm.CacheDir, c.MkDir()) |
539 | + |
540 | + s.service = NewFakeJujuService(s.State, s.APIState, s.options) |
541 | + err := s.service.Initialize() |
542 | + c.Assert(err, gc.IsNil) |
543 | + |
544 | + controller := s.Factory.MakeMachine(c, &factory.MachineParams{ |
545 | + InstanceId: s.service.NewInstanceId(), |
546 | + Nonce: agent.BootstrapNonce, |
547 | + Jobs: []state.MachineJob{state.JobManageModel, state.JobHostUnits}, |
548 | + Series: s.options.Series, |
549 | + }) |
550 | + err = s.service.InitializeController(controller) |
551 | + c.Assert(err, gc.IsNil) |
552 | +} |
553 | + |
554 | +func (s *FakeJujuSuite) TestStart(c *gc.C) { |
555 | +} |
Command: make ci-test /ci.lscape. net/job/ latch-test- xenial/ 1032/
Result: Fail
Revno: 60
Branch: lp:~free.ekanayaka/fake-juju/initial-unit-tests
Jenkins: https:/