github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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 "github.com/juju/names" 8 jc "github.com/juju/testing/checkers" 9 gc "gopkg.in/check.v1" 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/testing" 16 ) 17 18 type volumesSuite struct{} 19 20 var _ = gc.Suite(&volumesSuite{}) 21 22 func (s *volumesSuite) TestVolumeParams(c *gc.C) { 23 s.testVolumeParams(c, &state.VolumeParams{ 24 Pool: "loop", 25 Size: 1024, 26 }, nil) 27 } 28 29 func (s *volumesSuite) TestVolumeParamsAlreadyProvisioned(c *gc.C) { 30 s.testVolumeParams(c, nil, &state.VolumeInfo{ 31 Pool: "loop", 32 Size: 1024, 33 }) 34 } 35 36 func (*volumesSuite) testVolumeParams(c *gc.C, volumeParams *state.VolumeParams, info *state.VolumeInfo) { 37 tag := names.NewVolumeTag("100") 38 p, err := storagecommon.VolumeParams( 39 &fakeVolume{tag: tag, params: volumeParams, info: info}, 40 nil, // StorageInstance 41 testing.CustomModelConfig(c, testing.Attrs{ 42 "resource-tags": "a=b c=", 43 }), 44 &fakePoolManager{}, 45 ) 46 c.Assert(err, jc.ErrorIsNil) 47 c.Assert(p, jc.DeepEquals, params.VolumeParams{ 48 VolumeTag: "volume-100", 49 Provider: "loop", 50 Size: 1024, 51 Tags: map[string]string{ 52 tags.JujuController: testing.ModelTag.Id(), 53 tags.JujuModel: testing.ModelTag.Id(), 54 "a": "b", 55 "c": "", 56 }, 57 }) 58 } 59 60 func (*volumesSuite) TestVolumeParamsStorageTags(c *gc.C) { 61 volumeTag := names.NewVolumeTag("100") 62 storageTag := names.NewStorageTag("mystore/0") 63 unitTag := names.NewUnitTag("mysql/123") 64 p, err := storagecommon.VolumeParams( 65 &fakeVolume{tag: volumeTag, params: &state.VolumeParams{ 66 Pool: "loop", Size: 1024, 67 }}, 68 &fakeStorageInstance{tag: storageTag, owner: unitTag}, 69 testing.CustomModelConfig(c, nil), 70 &fakePoolManager{}, 71 ) 72 c.Assert(err, jc.ErrorIsNil) 73 c.Assert(p, jc.DeepEquals, params.VolumeParams{ 74 VolumeTag: "volume-100", 75 Provider: "loop", 76 Size: 1024, 77 Tags: map[string]string{ 78 tags.JujuController: testing.ModelTag.Id(), 79 tags.JujuModel: testing.ModelTag.Id(), 80 tags.JujuStorageInstance: "mystore/0", 81 tags.JujuStorageOwner: "mysql/123", 82 }, 83 }) 84 }