File: requests_test.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, bullseye-backports
  • size: 10,224 kB
  • sloc: sh: 125; makefile: 21
file content (98 lines) | stat: -rw-r--r-- 2,656 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package testing

import (
	"testing"

	"github.com/gophercloud/gophercloud/openstack/baremetalintrospection/v1/introspection"
	"github.com/gophercloud/gophercloud/pagination"
	th "github.com/gophercloud/gophercloud/testhelper"
	"github.com/gophercloud/gophercloud/testhelper/client"
)

func TestListIntrospections(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListIntrospectionsSuccessfully(t)

	pages := 0
	err := introspection.ListIntrospections(client.ServiceClient(), introspection.ListIntrospectionsOpts{}).EachPage(func(page pagination.Page) (bool, error) {
		pages++

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

		if len(actual) != 2 {
			t.Fatalf("Expected 2 introspections, got %d", len(actual))
		}
		th.CheckDeepEquals(t, IntrospectionFoo, actual[0])
		th.CheckDeepEquals(t, IntrospectionBar, actual[1])

		return true, nil
	})

	th.AssertNoErr(t, err)

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

func TestGetIntrospectionStatus(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleGetIntrospectionStatusSuccessfully(t)

	c := client.ServiceClient()
	actual, err := introspection.GetIntrospectionStatus(c, "c244557e-899f-46fa-a1ff-5b2c6718616b").Extract()
	if err != nil {
		t.Fatalf("Unexpected Get error: %v", err)
	}

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

func TestStartIntrospection(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleStartIntrospectionSuccessfully(t)

	c := client.ServiceClient()
	err := introspection.StartIntrospection(c, "c244557e-899f-46fa-a1ff-5b2c6718616b", introspection.StartOpts{}).ExtractErr()
	th.AssertNoErr(t, err)
}

func TestAbortIntrospection(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleAbortIntrospectionSuccessfully(t)

	c := client.ServiceClient()
	err := introspection.AbortIntrospection(c, "c244557e-899f-46fa-a1ff-5b2c6718616b").ExtractErr()
	th.AssertNoErr(t, err)
}

func TestGetIntrospectionData(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleGetIntrospectionDataSuccessfully(t)

	c := client.ServiceClient()
	actual, err := introspection.GetIntrospectionData(c, "c244557e-899f-46fa-a1ff-5b2c6718616b").Extract()
	if err != nil {
		t.Fatalf("Unexpected Get error: %v", err)
	}

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

func TestReApplyIntrospection(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleReApplyIntrospectionSuccessfully(t)

	c := client.ServiceClient()
	err := introspection.ReApplyIntrospection(c, "c244557e-899f-46fa-a1ff-5b2c6718616b").ExtractErr()
	th.AssertNoErr(t, err)
}