github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/core/network/zone_test.go (about) 1 // Copyright 2020 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package network 5 6 import ( 7 "github.com/juju/errors" 8 jujutesting "github.com/juju/testing" 9 jc "github.com/juju/testing/checkers" 10 gc "gopkg.in/check.v1" 11 ) 12 13 type zoneSuite struct { 14 jujutesting.IsolationSuite 15 16 zones AvailabilityZones 17 } 18 19 var _ = gc.Suite(&zoneSuite{}) 20 21 func (s *zoneSuite) SetUpTest(c *gc.C) { 22 s.zones = AvailabilityZones{ 23 &az{name: "zone1", available: true}, 24 &az{name: "zone2"}, 25 } 26 27 s.IsolationSuite.SetUpTest(c) 28 } 29 30 func (s *zoneSuite) TestAvailabilityZones(c *gc.C) { 31 c.Assert(s.zones.Validate("zone1"), jc.ErrorIsNil) 32 c.Assert(s.zones.Validate("zone2"), gc.ErrorMatches, `zone "zone2" is unavailable`) 33 c.Assert(s.zones.Validate("zone3"), jc.Satisfies, errors.IsNotValid) 34 } 35 36 type az struct { 37 name string 38 available bool 39 } 40 41 var _ = AvailabilityZone(&az{}) 42 43 func (a *az) Name() string { 44 return a.name 45 } 46 47 func (a *az) Available() bool { 48 return a.available 49 }