~rogpeppe/juju-core/axwalk-lp1300889-disable-mongo-keyfile

« back to all changes in this revision

Viewing changes to environs/tools/tools_test.go

  • Committer: Ian Booth
  • Date: 2013-08-13 04:55:12 UTC
  • mto: (1603.8.2 simplify-tools-search)
  • mto: This revision was merged to the branch mainline in revision 1680.
  • Revision ID: ian.booth@canonical.com-20130813045512-e68m4emfaoyn01h9
Add support for parsing and validating tools metadata

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// Copyright 2012, 2013 Canonical Ltd.
2
2
// Licensed under the AGPLv3, see LICENCE file for details.
3
3
 
4
 
package environs_test
 
4
package tools_test
5
5
 
6
6
import (
7
7
        . "launchpad.net/gocheck"
8
8
 
9
 
        "launchpad.net/juju-core/agent/tools"
 
9
        agenttools "launchpad.net/juju-core/agent/tools"
10
10
        "launchpad.net/juju-core/constraints"
11
11
        "launchpad.net/juju-core/environs"
12
12
        "launchpad.net/juju-core/environs/dummy"
13
13
        envtesting "launchpad.net/juju-core/environs/testing"
 
14
        "launchpad.net/juju-core/environs/tools"
14
15
        "launchpad.net/juju-core/errors"
15
16
        "launchpad.net/juju-core/testing"
16
17
        "launchpad.net/juju-core/version"
128
129
}{{
129
130
        info:  "none available anywhere",
130
131
        major: 1,
131
 
        err:   tools.ErrNoTools,
 
132
        err:   agenttools.ErrNoTools,
132
133
}, {
133
134
        info:    "private tools only, none matching",
134
135
        major:   1,
135
136
        private: v220all,
136
 
        err:     tools.ErrNoMatches,
 
137
        err:     agenttools.ErrNoMatches,
137
138
}, {
138
139
        info:    "tools found in private bucket",
139
140
        major:   1,
155
156
        major:   1,
156
157
        private: v220all,
157
158
        public:  vAll,
158
 
        err:     tools.ErrNoMatches,
 
159
        err:     agenttools.ErrNoMatches,
159
160
}}
160
161
 
161
162
func (s *ToolsSuite) TestFindAvailableTools(c *C) {
164
165
                s.Reset(c, nil)
165
166
                private := s.uploadPrivate(c, test.private...)
166
167
                public := s.uploadPublic(c, test.public...)
167
 
                actual, err := environs.FindAvailableTools(s.env, test.major)
 
168
                actual, err := tools.FindAvailableTools(s.env, test.major)
168
169
                if test.err != nil {
169
170
                        if len(actual) > 0 {
170
171
                                c.Logf(actual.String())
174
175
                }
175
176
                source := private
176
177
                if len(source) == 0 {
177
 
                        // We only use the public bucket if the private one has *no* tools.
 
178
                        // We only use the public bucket if the private one has *no* agenttools.
178
179
                        source = public
179
180
                }
180
181
                expect := map[version.Binary]string{}
199
200
        info:          "no tools at all",
200
201
        cliVersion:    v100p64,
201
202
        defaultSeries: "precise",
202
 
        err:           tools.ErrNoTools,
 
203
        err:           agenttools.ErrNoTools,
203
204
}, {
204
205
        info:          "released cli: use newest compatible release version",
205
206
        available:     vAll,
269
270
        available:     v220all,
270
271
        cliVersion:    v100p64,
271
272
        defaultSeries: "precise",
272
 
        err:           tools.ErrNoMatches,
 
273
        err:           agenttools.ErrNoMatches,
273
274
}, {
274
275
        info:          "released cli: major downgrades bad",
275
276
        available:     v100Xall,
276
277
        cliVersion:    v220p64,
277
278
        defaultSeries: "precise",
278
 
        err:           tools.ErrNoMatches,
 
279
        err:           agenttools.ErrNoMatches,
279
280
}, {
280
281
        info:          "released cli: no matching series",
281
282
        available:     vAll,
282
283
        cliVersion:    v100p64,
283
284
        defaultSeries: "raring",
284
 
        err:           tools.ErrNoMatches,
 
285
        err:           agenttools.ErrNoMatches,
285
286
}, {
286
287
        info:          "released cli: no matching arches",
287
288
        available:     vAll,
288
289
        cliVersion:    v100p64,
289
290
        defaultSeries: "precise",
290
291
        constraints:   "arch=arm",
291
 
        err:           tools.ErrNoMatches,
 
292
        err:           agenttools.ErrNoMatches,
292
293
}, {
293
294
        info:          "released cli: specific bad major 1",
294
295
        available:     vAll,
295
296
        cliVersion:    v220p64,
296
297
        agentVersion:  v120,
297
298
        defaultSeries: "precise",
298
 
        err:           tools.ErrNoMatches,
 
299
        err:           agenttools.ErrNoMatches,
299
300
}, {
300
301
        info:          "released cli: specific bad major 2",
301
302
        available:     vAll,
302
303
        cliVersion:    v120p64,
303
304
        agentVersion:  v220,
304
305
        defaultSeries: "precise",
305
 
        err:           tools.ErrNoMatches,
 
306
        err:           agenttools.ErrNoMatches,
306
307
}, {
307
308
        info:          "released cli: ignore dev tools 1",
308
309
        available:     v110all,
309
310
        cliVersion:    v100p64,
310
311
        defaultSeries: "precise",
311
 
        err:           tools.ErrNoMatches,
 
312
        err:           agenttools.ErrNoMatches,
312
313
}, {
313
314
        info:          "released cli: ignore dev tools 2",
314
315
        available:     v110all,
315
316
        cliVersion:    v120p64,
316
317
        defaultSeries: "precise",
317
 
        err:           tools.ErrNoMatches,
 
318
        err:           agenttools.ErrNoMatches,
318
319
}, {
319
320
        info:          "released cli: ignore dev tools 3",
320
321
        available:     []version.Binary{v1001p64},
321
322
        cliVersion:    v100p64,
322
323
        defaultSeries: "precise",
323
 
        err:           tools.ErrNoMatches,
 
324
        err:           agenttools.ErrNoMatches,
324
325
}, {
325
326
        info:          "released cli with dev setting picks newest matching 1",
326
327
        available:     v100Xall,
385
386
                }
386
387
 
387
388
                cons := constraints.MustParse(test.constraints)
388
 
                actual, err := environs.FindBootstrapTools(s.env, cons)
 
389
                actual, err := tools.FindBootstrapTools(s.env, cons)
389
390
                if test.err != nil {
390
391
                        if len(actual) > 0 {
391
392
                                c.Logf(actual.String())
420
421
        info:         "nothing at all",
421
422
        agentVersion: v120,
422
423
        series:       "precise",
423
 
        err:          tools.ErrNoTools,
 
424
        err:          agenttools.ErrNoTools,
424
425
}, {
425
426
        info:         "nothing matching 1",
426
427
        available:    v100Xall,
427
428
        agentVersion: v120,
428
429
        series:       "precise",
429
 
        err:          tools.ErrNoMatches,
 
430
        err:          agenttools.ErrNoMatches,
430
431
}, {
431
432
        info:         "nothing matching 2",
432
433
        available:    v120all,
433
434
        agentVersion: v110,
434
435
        series:       "precise",
435
 
        err:          tools.ErrNoMatches,
 
436
        err:          agenttools.ErrNoMatches,
436
437
}, {
437
438
        info:         "nothing matching 3",
438
439
        available:    v120q,
439
440
        agentVersion: v120,
440
441
        series:       "precise",
441
 
        err:          tools.ErrNoMatches,
 
442
        err:          agenttools.ErrNoMatches,
442
443
}, {
443
444
        info:         "nothing matching 4",
444
445
        available:    v120q,
445
446
        agentVersion: v120,
446
447
        series:       "quantal",
447
448
        constraints:  "arch=arm",
448
 
        err:          tools.ErrNoMatches,
 
449
        err:          agenttools.ErrNoMatches,
449
450
}, {
450
451
        info:         "actual match 1",
451
452
        available:    vAll,
480
481
                }
481
482
 
482
483
                cons := constraints.MustParse(test.constraints)
483
 
                actual, err := environs.FindInstanceTools(s.env, test.series, cons)
 
484
                actual, err := tools.FindInstanceTools(s.env, test.series, cons)
484
485
                if test.err != nil {
485
486
                        if len(actual) > 0 {
486
487
                                c.Logf(actual.String())
505
506
}{{
506
507
        info: "nothing available",
507
508
        seek: v100p64,
508
 
        err:  tools.ErrNoTools,
 
509
        err:  agenttools.ErrNoTools,
509
510
}, {
510
511
        info:    "only non-matches available in private",
511
512
        private: append(v110all, v100p32, v100q64, v1001p64),
512
513
        seek:    v100p64,
513
 
        err:     tools.ErrNoMatches,
 
514
        err:     agenttools.ErrNoMatches,
514
515
}, {
515
516
        info:    "exact match available in private",
516
517
        private: []version.Binary{v100p64},
519
520
        info:    "only non-matches available in public",
520
521
        private: append(v110all, v100p32, v100q64, v1001p64),
521
522
        seek:    v100p64,
522
 
        err:     tools.ErrNoMatches,
 
523
        err:     agenttools.ErrNoMatches,
523
524
}, {
524
525
        info:   "exact match available in public",
525
526
        public: []version.Binary{v100p64},
529
530
        private: v110all,
530
531
        public:  []version.Binary{v100p64},
531
532
        seek:    v100p64,
532
 
        err:     tools.ErrNoMatches,
 
533
        err:     agenttools.ErrNoMatches,
533
534
}}
534
535
 
535
536
func (s *ToolsSuite) TestFindExactTools(c *C) {
538
539
                s.Reset(c, nil)
539
540
                private := s.uploadPrivate(c, test.private...)
540
541
                public := s.uploadPublic(c, test.public...)
541
 
                actual, err := environs.FindExactTools(s.env, test.seek)
 
542
                actual, err := tools.FindExactTools(s.env, test.seek)
542
543
                if test.err == nil {
543
544
                        c.Check(err, IsNil)
544
545
                        c.Check(actual.Version, Equals, test.seek)
545
546
                        source := private
546
547
                        if len(source) == 0 {
547
 
                                // We only use the public bucket if the private one has *no* tools.
 
548
                                // We only use the public bucket if the private one has *no* agenttools.
548
549
                                source = public
549
550
                        }
550
551
                        c.Check(actual.URL, DeepEquals, source[actual.Version])
556
557
 
557
558
// fakeToolsForSeries fakes a Tools object with just enough information for
558
559
// testing the handling its OS series.
559
 
func fakeToolsForSeries(series string) *tools.Tools {
560
 
        return &tools.Tools{Version: version.Binary{Series: series}}
 
560
func fakeToolsForSeries(series string) *agenttools.Tools {
 
561
        return &agenttools.Tools{Version: version.Binary{Series: series}}
561
562
}
562
563
 
563
 
// fakeToolsList fakes a tools.List containing Tools objects for the given
 
564
// fakeToolsList fakes a agenttools.List containing Tools objects for the given
564
565
// respective series, in the same number and order.
565
 
func fakeToolsList(series ...string) tools.List {
566
 
        list := tools.List{}
 
566
func fakeToolsList(series ...string) agenttools.List {
 
567
        list := agenttools.List{}
567
568
        for _, name := range series {
568
569
                list = append(list, fakeToolsForSeries(name))
569
570
        }
571
572
}
572
573
 
573
574
func (s *ToolsSuite) TestCheckToolsSeriesRequiresTools(c *C) {
574
 
        err := environs.CheckToolsSeries(fakeToolsList(), "precise")
 
575
        err := tools.CheckToolsSeries(fakeToolsList(), "precise")
575
576
        c.Assert(err, NotNil)
576
577
        c.Check(err, ErrorMatches, "expected single series, got \\[\\]")
577
578
}
580
581
        names := []string{"precise", "raring"}
581
582
        for _, series := range names {
582
583
                list := fakeToolsList(series)
583
 
                err := environs.CheckToolsSeries(list, series)
 
584
                err := tools.CheckToolsSeries(list, series)
584
585
                c.Check(err, IsNil)
585
586
        }
586
587
}
588
589
func (s *ToolsSuite) TestCheckToolsSeriesAcceptsMultipleForSameSeries(c *C) {
589
590
        series := "quantal"
590
591
        list := fakeToolsList(series, series, series)
591
 
        err := environs.CheckToolsSeries(list, series)
 
592
        err := tools.CheckToolsSeries(list, series)
592
593
        c.Check(err, IsNil)
593
594
}
594
595
 
595
596
func (s *ToolsSuite) TestCheckToolsSeriesRejectsToolsForOtherSeries(c *C) {
596
597
        list := fakeToolsList("hoary")
597
 
        err := environs.CheckToolsSeries(list, "warty")
 
598
        err := tools.CheckToolsSeries(list, "warty")
598
599
        c.Assert(err, NotNil)
599
600
        c.Check(err, ErrorMatches, "tools mismatch: expected series warty, got hoary")
600
601
}
601
602
 
602
603
func (s *ToolsSuite) TestCheckToolsSeriesRejectsToolsForMixedSeries(c *C) {
603
604
        list := fakeToolsList("precise", "raring")
604
 
        err := environs.CheckToolsSeries(list, "precise")
 
605
        err := tools.CheckToolsSeries(list, "precise")
605
606
        c.Assert(err, NotNil)
606
607
        c.Check(err, ErrorMatches, "expected single series, got .*")
607
608
}