blob: 3579f16454f34c08363ea8e5b4928e2e6793f1c1 [file] [log] [blame]
Michal Kobusf6113582019-09-09 15:58:21 +02001package testing
2
3import (
4 "testing"
5
6 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/baremetal/v1/allocations"
7 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
8 th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
9 "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
10)
11
12func TestListAllocations(t *testing.T) {
13 th.SetupHTTP()
14 defer th.TeardownHTTP()
15 HandleAllocationListSuccessfully(t)
16
17 pages := 0
18 err := allocations.List(client.ServiceClient(), allocations.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
19 pages++
20
21 actual, err := allocations.ExtractAllocations(page)
22 if err != nil {
23 return false, err
24 }
25
26 if len(actual) != 2 {
27 t.Fatalf("Expected 2 allocations, got %d", len(actual))
28 }
29 th.AssertEquals(t, "5344a3e2-978a-444e-990a-cbf47c62ef88", actual[0].UUID)
30 th.AssertEquals(t, "eff80f47-75f0-4d41-b1aa-cf07c201adac", actual[1].UUID)
31
32 return true, nil
33 })
34
35 th.AssertNoErr(t, err)
36
37 if pages != 1 {
38 t.Errorf("Expected 1 page, saw %d", pages)
39 }
40}
41
42func TestCreateAllocation(t *testing.T) {
43 th.SetupHTTP()
44 defer th.TeardownHTTP()
45 HandleAllocationCreationSuccessfully(t, SingleAllocationBody)
46
47 actual, err := allocations.Create(client.ServiceClient(), allocations.CreateOpts{
48 Name: "allocation-1",
49 ResourceClass: "baremetal",
50 CandidateNodes: []string{"344a3e2-978a-444e-990a-cbf47c62ef88"},
51 Traits: []string{"foo"},
52 }).Extract()
53 th.AssertNoErr(t, err)
54
55 th.CheckDeepEquals(t, Allocation1, *actual)
56}
57
58func TestDeleteAllocation(t *testing.T) {
59 th.SetupHTTP()
60 defer th.TeardownHTTP()
61 HandleAllocationDeletionSuccessfully(t)
62
63 res := allocations.Delete(client.ServiceClient(), "344a3e2-978a-444e-990a-cbf47c62ef88")
64 th.AssertNoErr(t, res.Err)
65}
66
67func TestGetAllocation(t *testing.T) {
68 th.SetupHTTP()
69 defer th.TeardownHTTP()
70 HandleAllocationGetSuccessfully(t)
71
72 c := client.ServiceClient()
73 actual, err := allocations.Get(c, "344a3e2-978a-444e-990a-cbf47c62ef88").Extract()
74 if err != nil {
75 t.Fatalf("Unexpected Get error: %v", err)
76 }
77
78 th.CheckDeepEquals(t, Allocation1, *actual)
79}