1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
package testing
import (
"strings"
"testing"
"github.com/gophercloud/gophercloud/openstack/clustering/v1/nodes"
"github.com/gophercloud/gophercloud/pagination"
th "github.com/gophercloud/gophercloud/testhelper"
fake "github.com/gophercloud/gophercloud/testhelper/client"
)
func TestCreateNode(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleCreateSuccessfully(t)
createOpts := nodes.CreateOpts{
ClusterID: "e395be1e-8d8e-43bb-bd6c-943eccf76a6d",
Metadata: map[string]interface{}{
"foo": "bar",
"test": map[string]interface{}{
"nil_interface": interface{}(nil),
"float_value": float64(123.3),
"string_value": "test_string",
"bool_value": false,
},
},
Name: "node-e395be1e-002",
ProfileID: "d8a48377-f6a3-4af4-bbbb-6e8bcaa0cbc0",
Role: "",
}
res := nodes.Create(fake.ServiceClient(), createOpts)
th.AssertNoErr(t, res.Err)
requestID := res.Header.Get("X-Openstack-Request-Id")
th.AssertEquals(t, "req-3791a089-9d46-4671-a3f9-55e95e55d2b4", requestID)
location := res.Header.Get("Location")
th.AssertEquals(t, "http://senlin.cloud.blizzard.net:8778/v1/actions/ffd94dd8-6266-4887-9a8c-5b78b72136da", location)
locationFields := strings.Split(location, "actions/")
actionID := locationFields[1]
th.AssertEquals(t, "ffd94dd8-6266-4887-9a8c-5b78b72136da", actionID)
actual, err := res.Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, ExpectedCreate, *actual)
}
func TestListNodes(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleListSuccessfully(t)
count := 0
err := nodes.List(fake.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
actual, err := nodes.ExtractNodes(page)
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, ExpectedList, actual)
count++
return true, nil
})
th.AssertNoErr(t, err)
th.AssertEquals(t, count, 1)
}
func TestDeleteNode(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleDeleteSuccessfully(t)
deleteResult := nodes.Delete(fake.ServiceClient(), "6dc6d336e3fc4c0a951b5698cd1236ee")
th.AssertNoErr(t, deleteResult.ExtractErr())
}
func TestGetNode(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleGetSuccessfully(t)
actual, err := nodes.Get(fake.ServiceClient(), "573aa1ba-bf45-49fd-907d-6b5d6e6adfd3").Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, ExpectedGet, *actual)
}
func TestUpdateNode(t *testing.T) {
th.SetupHTTP()
defer th.TeardownHTTP()
HandleUpdateSuccessfully(t)
nodeOpts := nodes.UpdateOpts{
Name: "node-e395be1e-002",
}
actual, err := nodes.Update(fake.ServiceClient(), ExpectedUpdate.ID, nodeOpts).Extract()
th.AssertNoErr(t, err)
th.AssertDeepEquals(t, ExpectedUpdate, *actual)
}
|