github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/apiserver/common/storagecommon/volumes_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package storagecommon_test 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 "gopkg.in/juju/names.v2" 10 11 "github.com/juju/juju/apiserver/common/storagecommon" 12 "github.com/juju/juju/apiserver/params" 13 "github.com/juju/juju/environs/tags" 14 "github.com/juju/juju/state" 15 "github.com/juju/juju/storage/provider" 16 "github.com/juju/juju/testing" 17 ) 18 19 type volumesSuite struct{} 20 21 var _ = gc.Suite(&volumesSuite{}) 22 23 func (s *volumesSuite) TestVolumeParams(c *gc.C) { 24 s.testVolumeParams(c, &state.VolumeParams{ 25 Pool: "loop", 26 Size: 1024, 27 }, nil) 28 } 29 30 func (s *volumesSuite) TestVolumeParamsAlreadyProvisioned(c *gc.C) { 31 s.testVolumeParams(c, nil, &state.VolumeInfo{ 32 Pool: "loop", 33 Size: 1024, 34 }) 35 } 36 37 func (*volumesSuite) testVolumeParams(c *gc.C, volumeParams *state.VolumeParams, info *state.VolumeInfo) { 38 tag := names.NewVolumeTag("100") 39 p, err := storagecommon.VolumeParams( 40 &fakeVolume{tag: tag, params: volumeParams, info: info}, 41 nil, // StorageInstance 42 testing.ModelTag.Id(), 43 testing.ControllerTag.Id(), 44 testing.CustomModelConfig(c, testing.Attrs{ 45 "resource-tags": "a=b c=", 46 }), 47 &fakePoolManager{}, 48 provider.CommonStorageProviders(), 49 ) 50 c.Assert(err, jc.ErrorIsNil) 51 c.Assert(p, jc.DeepEquals, params.VolumeParams{ 52 VolumeTag: "volume-100", 53 Provider: "loop", 54 Size: 1024, 55 Tags: map[string]string{ 56 tags.JujuController: testing.ControllerTag.Id(), 57 tags.JujuModel: testing.ModelTag.Id(), 58 "a": "b", 59 "c": "", 60 }, 61 }) 62 } 63 64 func (*volumesSuite) TestVolumeParamsStorageTags(c *gc.C) { 65 volumeTag := names.NewVolumeTag("100") 66 storageTag := names.NewStorageTag("mystore/0") 67 unitTag := names.NewUnitTag("mysql/123") 68 p, err := storagecommon.VolumeParams( 69 &fakeVolume{tag: volumeTag, params: &state.VolumeParams{ 70 Pool: "loop", Size: 1024, 71 }}, 72 &fakeStorageInstance{tag: storageTag, owner: unitTag}, 73 testing.ModelTag.Id(), 74 testing.ControllerTag.Id(), 75 testing.CustomModelConfig(c, nil), 76 &fakePoolManager{}, 77 provider.CommonStorageProviders(), 78 ) 79 c.Assert(err, jc.ErrorIsNil) 80 c.Assert(p, jc.DeepEquals, params.VolumeParams{ 81 VolumeTag: "volume-100", 82 Provider: "loop", 83 Size: 1024, 84 Tags: map[string]string{ 85 tags.JujuController: testing.ControllerTag.Id(), 86 tags.JujuModel: testing.ModelTag.Id(), 87 tags.JujuStorageInstance: "mystore/0", 88 tags.JujuStorageOwner: "mysql/123", 89 }, 90 }) 91 }