github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/core/assumes/featureset_test.go (about) 1 // Copyright 2021 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package assumes 5 6 import ( 7 "github.com/juju/testing" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 ) 11 12 type FeatureSetSuite struct { 13 testing.IsolationSuite 14 } 15 16 var _ = gc.Suite(&FeatureSetSuite{}) 17 18 func (s *FeatureSetSuite) TestAsList(c *gc.C) { 19 var fs FeatureSet 20 fs.Add( 21 Feature{Name: "zzz"}, 22 Feature{Name: "abc"}, 23 Feature{Name: "efg"}, 24 ) 25 26 exp := []Feature{ 27 {Name: "abc"}, 28 {Name: "efg"}, 29 {Name: "zzz"}, 30 } 31 32 c.Assert(fs.AsList(), gc.DeepEquals, exp, gc.Commentf("expected AsList() to return the feature list sorted by name")) 33 } 34 35 func (s *SatCheckerSuite) TestMerge(c *gc.C) { 36 var fs1 FeatureSet 37 fs1.Add( 38 Feature{Name: "zzz"}, 39 Feature{Name: "efg"}, 40 ) 41 42 var fs2 FeatureSet 43 fs2.Add( 44 Feature{Name: "abc"}, 45 Feature{Name: "efg"}, 46 ) 47 48 exp := []Feature{ 49 {Name: "abc"}, 50 {Name: "efg"}, 51 {Name: "zzz"}, 52 } 53 54 fs1.Merge(fs2) 55 56 c.Assert(fs1.AsList(), gc.DeepEquals, exp, gc.Commentf("expected AsList() to return the union of the two sets with duplicates removed")) 57 } 58 59 func (s *SatCheckerSuite) TestGet(c *gc.C) { 60 var fs FeatureSet 61 fs.Add( 62 Feature{Name: "zzz"}, 63 ) 64 65 _, found := fs.Get("zzz") 66 c.Assert(found, jc.IsTrue) 67 68 _, found = fs.Get("bogus!") 69 c.Assert(found, jc.IsFalse) 70 }