File: requests_test.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (79 lines) | stat: -rw-r--r-- 2,068 bytes parent folder | download | duplicates (2)
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
package testing

import (
	"testing"

	"github.com/gophercloud/gophercloud/openstack/baremetal/v1/allocations"
	"github.com/gophercloud/gophercloud/pagination"
	th "github.com/gophercloud/gophercloud/testhelper"
	"github.com/gophercloud/gophercloud/testhelper/client"
)

func TestListAllocations(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleAllocationListSuccessfully(t)

	pages := 0
	err := allocations.List(client.ServiceClient(), allocations.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		pages++

		actual, err := allocations.ExtractAllocations(page)
		if err != nil {
			return false, err
		}

		if len(actual) != 2 {
			t.Fatalf("Expected 2 allocations, got %d", len(actual))
		}
		th.AssertEquals(t, "5344a3e2-978a-444e-990a-cbf47c62ef88", actual[0].UUID)
		th.AssertEquals(t, "eff80f47-75f0-4d41-b1aa-cf07c201adac", actual[1].UUID)

		return true, nil
	})

	th.AssertNoErr(t, err)

	if pages != 1 {
		t.Errorf("Expected 1 page, saw %d", pages)
	}
}

func TestCreateAllocation(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleAllocationCreationSuccessfully(t, SingleAllocationBody)

	actual, err := allocations.Create(client.ServiceClient(), allocations.CreateOpts{
		Name:           "allocation-1",
		ResourceClass:  "baremetal",
		CandidateNodes: []string{"344a3e2-978a-444e-990a-cbf47c62ef88"},
		Traits:         []string{"foo"},
	}).Extract()
	th.AssertNoErr(t, err)

	th.CheckDeepEquals(t, Allocation1, *actual)
}

func TestDeleteAllocation(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleAllocationDeletionSuccessfully(t)

	res := allocations.Delete(client.ServiceClient(), "344a3e2-978a-444e-990a-cbf47c62ef88")
	th.AssertNoErr(t, res.Err)
}

func TestGetAllocation(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleAllocationGetSuccessfully(t)

	c := client.ServiceClient()
	actual, err := allocations.Get(c, "344a3e2-978a-444e-990a-cbf47c62ef88").Extract()
	if err != nil {
		t.Fatalf("Unexpected Get error: %v", err)
	}

	th.CheckDeepEquals(t, Allocation1, *actual)
}