github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/diskconfig/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/diskconfig" 7 "github.com/huaweicloud/golangsdk/openstack/compute/v2/servers" 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 ) 10 11 func TestCreateOpts(t *testing.T) { 12 base := servers.CreateOpts{ 13 Name: "createdserver", 14 ImageRef: "asdfasdfasdf", 15 FlavorRef: "performance1-1", 16 } 17 18 ext := diskconfig.CreateOptsExt{ 19 CreateOptsBuilder: base, 20 DiskConfig: diskconfig.Manual, 21 } 22 23 expected := ` 24 { 25 "server": { 26 "name": "createdserver", 27 "imageRef": "asdfasdfasdf", 28 "flavorRef": "performance1-1", 29 "OS-DCF:diskConfig": "MANUAL" 30 } 31 } 32 ` 33 actual, err := ext.ToServerCreateMap() 34 th.AssertNoErr(t, err) 35 th.CheckJSONEquals(t, expected, actual) 36 } 37 38 func TestRebuildOpts(t *testing.T) { 39 base := servers.RebuildOpts{ 40 Name: "rebuiltserver", 41 AdminPass: "swordfish", 42 ImageID: "asdfasdfasdf", 43 } 44 45 ext := diskconfig.RebuildOptsExt{ 46 RebuildOptsBuilder: base, 47 DiskConfig: diskconfig.Auto, 48 } 49 50 actual, err := ext.ToServerRebuildMap() 51 th.AssertNoErr(t, err) 52 53 expected := ` 54 { 55 "rebuild": { 56 "name": "rebuiltserver", 57 "imageRef": "asdfasdfasdf", 58 "adminPass": "swordfish", 59 "OS-DCF:diskConfig": "AUTO" 60 } 61 } 62 ` 63 th.CheckJSONEquals(t, expected, actual) 64 } 65 66 func TestResizeOpts(t *testing.T) { 67 base := servers.ResizeOpts{ 68 FlavorRef: "performance1-8", 69 } 70 71 ext := diskconfig.ResizeOptsExt{ 72 ResizeOptsBuilder: base, 73 DiskConfig: diskconfig.Auto, 74 } 75 76 actual, err := ext.ToServerResizeMap() 77 th.AssertNoErr(t, err) 78 79 expected := ` 80 { 81 "resize": { 82 "flavorRef": "performance1-8", 83 "OS-DCF:diskConfig": "AUTO" 84 } 85 } 86 ` 87 th.CheckJSONEquals(t, expected, actual) 88 }