github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/floatingips/testing/requests_test.go (about) 1 package testing 2 3 import ( 4 "testing" 5 6 "github.com/huaweicloud/golangsdk/openstack/compute/v2/extensions/floatingips" 7 "github.com/huaweicloud/golangsdk/pagination" 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 "github.com/huaweicloud/golangsdk/testhelper/client" 10 ) 11 12 func TestList(t *testing.T) { 13 th.SetupHTTP() 14 defer th.TeardownHTTP() 15 HandleListSuccessfully(t) 16 17 count := 0 18 err := floatingips.List(client.ServiceClient()).EachPage(func(page pagination.Page) (bool, error) { 19 count++ 20 actual, err := floatingips.ExtractFloatingIPs(page) 21 th.AssertNoErr(t, err) 22 th.CheckDeepEquals(t, ExpectedFloatingIPsSlice, actual) 23 24 return true, nil 25 }) 26 th.AssertNoErr(t, err) 27 th.CheckEquals(t, 1, count) 28 } 29 30 func TestCreate(t *testing.T) { 31 th.SetupHTTP() 32 defer th.TeardownHTTP() 33 HandleCreateSuccessfully(t) 34 35 actual, err := floatingips.Create(client.ServiceClient(), floatingips.CreateOpts{ 36 Pool: "nova", 37 }).Extract() 38 th.AssertNoErr(t, err) 39 th.CheckDeepEquals(t, &CreatedFloatingIP, actual) 40 } 41 42 func TestCreateWithNumericID(t *testing.T) { 43 th.SetupHTTP() 44 defer th.TeardownHTTP() 45 HandleCreateWithNumericIDSuccessfully(t) 46 47 actual, err := floatingips.Create(client.ServiceClient(), floatingips.CreateOpts{ 48 Pool: "nova", 49 }).Extract() 50 th.AssertNoErr(t, err) 51 th.CheckDeepEquals(t, &CreatedFloatingIP, actual) 52 } 53 54 func TestGet(t *testing.T) { 55 th.SetupHTTP() 56 defer th.TeardownHTTP() 57 HandleGetSuccessfully(t) 58 59 actual, err := floatingips.Get(client.ServiceClient(), "2").Extract() 60 th.AssertNoErr(t, err) 61 th.CheckDeepEquals(t, &SecondFloatingIP, actual) 62 } 63 64 func TestDelete(t *testing.T) { 65 th.SetupHTTP() 66 defer th.TeardownHTTP() 67 HandleDeleteSuccessfully(t) 68 69 err := floatingips.Delete(client.ServiceClient(), "1").ExtractErr() 70 th.AssertNoErr(t, err) 71 } 72 73 func TestAssociate(t *testing.T) { 74 th.SetupHTTP() 75 defer th.TeardownHTTP() 76 HandleAssociateSuccessfully(t) 77 78 associateOpts := floatingips.AssociateOpts{ 79 FloatingIP: "10.10.10.2", 80 } 81 82 err := floatingips.AssociateInstance(client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0", associateOpts).ExtractErr() 83 th.AssertNoErr(t, err) 84 } 85 86 func TestAssociateFixed(t *testing.T) { 87 th.SetupHTTP() 88 defer th.TeardownHTTP() 89 HandleAssociateFixedSuccessfully(t) 90 91 associateOpts := floatingips.AssociateOpts{ 92 FloatingIP: "10.10.10.2", 93 FixedIP: "166.78.185.201", 94 } 95 96 err := floatingips.AssociateInstance(client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0", associateOpts).ExtractErr() 97 th.AssertNoErr(t, err) 98 } 99 100 func TestDisassociateInstance(t *testing.T) { 101 th.SetupHTTP() 102 defer th.TeardownHTTP() 103 HandleDisassociateSuccessfully(t) 104 105 disassociateOpts := floatingips.DisassociateOpts{ 106 FloatingIP: "10.10.10.2", 107 } 108 109 err := floatingips.DisassociateInstance(client.ServiceClient(), "4d8c3732-a248-40ed-bebc-539a6ffd25c0", disassociateOpts).ExtractErr() 110 th.AssertNoErr(t, err) 111 }