github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/container/kvm/libvirt/domainxml_internal_test.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package libvirt 5 6 import ( 7 "github.com/juju/testing" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 10 ) 11 12 // gocheck boilerplate. 13 type domainXMLInternalSuite struct { 14 testing.IsolationSuite 15 } 16 17 var _ = gc.Suite(&domainXMLInternalSuite{}) 18 19 func (domainXMLInternalSuite) TestDeviceID(c *gc.C) { 20 table := []struct { 21 in int 22 want string 23 errMsg string 24 }{ 25 {0, "vda", ""}, 26 {4, "vde", ""}, 27 {15, "vdp", ""}, 28 {25, "vdz", ""}, 29 {-1, "", "got -1 but only support devices 0-25"}, 30 {26, "", "got 26 but only support devices 0-25"}, 31 {120, "", "got 120 but only support devices 0-25"}, 32 } 33 for i, test := range table { 34 c.Logf("test %d for input %d", i+1, test.in) 35 got, err := deviceID(test.in) 36 if err != nil { 37 c.Check(err, gc.ErrorMatches, test.errMsg) 38 c.Check(got, gc.Equals, "") 39 continue 40 } 41 c.Check(got, gc.Equals, test.want) 42 c.Check(err, jc.ErrorIsNil) 43 } 44 }