github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/core/migration/phase_internal_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package migration 5 6 import ( 7 "github.com/juju/utils/set" 8 gc "gopkg.in/check.v1" 9 10 coretesting "github.com/juju/juju/testing" 11 ) 12 13 type PhaseInternalSuite struct { 14 coretesting.BaseSuite 15 } 16 17 var _ = gc.Suite(new(PhaseInternalSuite)) 18 19 func (s *PhaseInternalSuite) TestForUnused(c *gc.C) { 20 usedPhases := set.NewStrings() 21 for source, targets := range validTransitions { 22 usedPhases.Add(source.String()) 23 for _, target := range targets { 24 usedPhases.Add(target.String()) 25 } 26 } 27 28 specialPhases := set.NewStrings( 29 UNKNOWN.String(), 30 NONE.String(), 31 ) 32 allValidPhases := set.NewStrings(phaseNames...).Difference(specialPhases) 33 c.Check(allValidPhases.Difference(usedPhases), gc.HasLen, 0) 34 35 // The special phases shouldn't appear in the transition map. 36 c.Check(usedPhases.Intersection(specialPhases), gc.HasLen, 0) 37 } 38 39 func (s *PhaseInternalSuite) TestForUnreachable(c *gc.C) { 40 const initialPhase = QUIESCE 41 allSources := set.NewStrings() 42 allTargets := set.NewStrings() 43 for source, targets := range validTransitions { 44 if source != initialPhase { 45 allSources.Add(source.String()) 46 } 47 for _, target := range targets { 48 allTargets.Add(target.String()) 49 } 50 } 51 52 // Each source must be referred to at least once. 53 c.Check(allSources.Difference(allTargets), gc.HasLen, 0) 54 }