~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/upgrades/upgrade_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
        coretesting.MgoTestPackage(t)
31
31
}
32
32
 
33
 
// assertStateSteps is a helper that ensures that the given
34
 
// state-based upgrade steps match what is expected for that version
35
 
// and that the steps have been added to the global upgrade operations
36
 
// list.
37
 
func assertStateSteps(c *gc.C, ver version.Number, expectedSteps []string) {
38
 
        findAndCheckSteps(c, (*upgrades.StateUpgradeOperations)(), ver, expectedSteps)
39
 
}
40
 
 
41
 
// assertSteps is a helper that ensures that the given API-based
42
 
// upgrade steps match what is expected for that version and that the
43
 
// steps have been added to the global upgrade operations list.
44
 
func assertSteps(c *gc.C, ver version.Number, expectedSteps []string) {
45
 
        findAndCheckSteps(c, (*upgrades.UpgradeOperations)(), ver, expectedSteps)
46
 
}
47
 
 
48
 
func findAndCheckSteps(c *gc.C, ops []upgrades.Operation, ver version.Number, expectedSteps []string) {
49
 
        for _, op := range ops {
 
33
func findStep(c *gc.C, ver version.Number, description string) upgrades.Step {
 
34
        for _, op := range (*upgrades.UpgradeOperations)() {
50
35
                if op.TargetVersion() == ver {
51
 
                        assertExpectedSteps(c, op.Steps(), expectedSteps)
52
 
                        return
 
36
                        for _, step := range op.Steps() {
 
37
                                if step.Description() == description {
 
38
                                        return step
 
39
                                }
 
40
                        }
53
41
                }
54
42
        }
55
 
        if len(expectedSteps) > 0 {
56
 
                c.Fatal("upgrade operations for this version are not hooked up")
57
 
        }
58
 
}
59
 
 
60
 
// assertExpectedSteps is a helper function used to check that the upgrade steps match
61
 
// what is expected for a version.
62
 
func assertExpectedSteps(c *gc.C, steps []upgrades.Step, expectedSteps []string) {
63
 
        c.Assert(steps, gc.HasLen, len(expectedSteps))
64
 
 
65
 
        var stepNames = make([]string, len(steps))
66
 
        for i, step := range steps {
67
 
                stepNames[i] = step.Description()
68
 
        }
69
 
        c.Assert(stepNames, gc.DeepEquals, expectedSteps)
 
43
        c.Fatalf("could not find step %q for %s", description, ver)
 
44
        return nil
70
45
}
71
46
 
72
47
type upgradeSuite struct {
669
644
func (s *upgradeSuite) TestStateUpgradeOperationsVersions(c *gc.C) {
670
645
        versions := extractUpgradeVersions(c, (*upgrades.StateUpgradeOperations)())
671
646
        c.Assert(versions, gc.DeepEquals, []string{
672
 
                "1.26-placeholder1",
 
647
                "2.0.0",
673
648
        })
674
649
}
675
650
 
676
651
func (s *upgradeSuite) TestUpgradeOperationsVersions(c *gc.C) {
677
652
        versions := extractUpgradeVersions(c, (*upgrades.UpgradeOperations)())
678
653
        c.Assert(versions, gc.DeepEquals, []string{
679
 
                "1.26-placeholder1",
 
654
                "2.0.0",
680
655
        })
681
656
}
682
657
 
685
660
        for _, utv := range ops {
686
661
                vers := utv.TargetVersion()
687
662
                // Upgrade steps should only be targeted at final versions (not alpha/beta).
688
 
                c.Check(vers.Tag, gc.Equals, "placeholder")
 
663
                c.Check(vers.Tag, gc.Equals, "")
689
664
                versions = append(versions, vers.String())
690
665
        }
691
666
        return versions