github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/base/channel_test.go (about) 1 // Copyright 2022 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package base 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 ChannelSuite struct { 13 testing.IsolationSuite 14 } 15 16 var _ = gc.Suite(&ChannelSuite{}) 17 18 func (s *ChannelSuite) TestParse(c *gc.C) { 19 ch, err := ParseChannel("22.04") 20 c.Assert(err, jc.ErrorIsNil) 21 c.Assert(ch, jc.DeepEquals, Channel{Track: "22.04"}) 22 ch, err = ParseChannel("22.04/edge") 23 c.Assert(err, jc.ErrorIsNil) 24 c.Assert(ch, jc.DeepEquals, Channel{Track: "22.04", Risk: "edge"}) 25 ch, err = ParseChannel("all") 26 c.Assert(err, jc.ErrorIsNil) 27 c.Assert(ch, jc.DeepEquals, Channel{Track: "all"}) 28 } 29 30 func (s *ChannelSuite) TestParseError(c *gc.C) { 31 _, err := ParseChannel("22.04/edge/foo") 32 c.Assert(err, gc.ErrorMatches, `channel is malformed and has too many components "22.04/edge/foo"`) 33 _, err = ParseChannel("22.04/foo") 34 c.Assert(err, gc.ErrorMatches, `risk in channel "22.04/foo" not valid`) 35 } 36 37 func (s *ChannelSuite) TestParseNormalise(c *gc.C) { 38 ch, err := ParseChannelNormalize("22.04") 39 c.Assert(err, jc.ErrorIsNil) 40 c.Assert(ch, jc.DeepEquals, Channel{Track: "22.04", Risk: "stable"}) 41 ch, err = ParseChannelNormalize("22.04/edge") 42 c.Assert(err, jc.ErrorIsNil) 43 c.Assert(ch, jc.DeepEquals, Channel{Track: "22.04", Risk: "edge"}) 44 } 45 46 func (s *ChannelSuite) TestMakeDefaultChannel(c *gc.C) { 47 ch := MakeDefaultChannel("22.04") 48 c.Assert(ch, jc.DeepEquals, Channel{Track: "22.04", Risk: "stable"}) 49 } 50 51 func (s *ChannelSuite) TestString(c *gc.C) { 52 c.Assert(Channel{Track: "22.04"}.String(), gc.Equals, "22.04") 53 c.Assert(Channel{Track: "22.04", Risk: "edge"}.String(), gc.Equals, "22.04/edge") 54 } 55 56 func (s *ChannelSuite) TestDisplayString(c *gc.C) { 57 c.Assert(Channel{Track: "18.04"}.DisplayString(), gc.Equals, "18.04") 58 c.Assert(Channel{Track: "20.04", Risk: "stable"}.DisplayString(), gc.Equals, "20.04") 59 c.Assert(Channel{Track: "22.04", Risk: "edge"}.DisplayString(), gc.Equals, "22.04/edge") 60 }