File: requests_test.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.0~git20180917.45f1c769-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,768 kB
  • sloc: sh: 98; makefile: 14
file content (144 lines) | stat: -rw-r--r-- 3,974 bytes parent folder | download | duplicates (3)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package testing

import (
	"testing"

	"github.com/gophercloud/gophercloud/openstack/keymanager/v1/containers"
	"github.com/gophercloud/gophercloud/pagination"
	th "github.com/gophercloud/gophercloud/testhelper"
	"github.com/gophercloud/gophercloud/testhelper/client"
)

func TestListContainers(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListContainersSuccessfully(t)

	count := 0
	err := containers.List(client.ServiceClient(), nil).EachPage(func(page pagination.Page) (bool, error) {
		count++

		actual, err := containers.ExtractContainers(page)
		th.AssertNoErr(t, err)

		th.AssertDeepEquals(t, ExpectedContainersSlice, actual)

		return true, nil
	})
	th.AssertNoErr(t, err)
	th.AssertEquals(t, count, 1)
}

func TestListContainersAllPages(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListContainersSuccessfully(t)

	allPages, err := containers.List(client.ServiceClient(), nil).AllPages()
	th.AssertNoErr(t, err)
	actual, err := containers.ExtractContainers(allPages)
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, ExpectedContainersSlice, actual)
}

func TestGetContainer(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleGetContainerSuccessfully(t)

	actual, err := containers.Get(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0").Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, FirstContainer, *actual)
}

func TestCreateContainer(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleCreateContainerSuccessfully(t)

	createOpts := containers.CreateOpts{
		Type: containers.GenericContainer,
		Name: "mycontainer",
		SecretRefs: []containers.SecretRef{
			{
				Name:      "mysecret",
				SecretRef: "http://barbican:9311/v1/secrets/1b8068c4-3bb6-4be6-8f1e-da0d1ea0b67c",
			},
		},
	}

	actual, err := containers.Create(client.ServiceClient(), createOpts).Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, FirstContainer, *actual)
}

func TestDeleteContainer(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleDeleteContainerSuccessfully(t)

	res := containers.Delete(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0")
	th.AssertNoErr(t, res.Err)
}

func TestListConsumers(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListConsumersSuccessfully(t)

	count := 0
	err := containers.ListConsumers(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0", nil).EachPage(func(page pagination.Page) (bool, error) {
		count++

		actual, err := containers.ExtractConsumers(page)
		th.AssertNoErr(t, err)

		th.AssertDeepEquals(t, ExpectedConsumersSlice, actual)

		return true, nil
	})
	th.AssertNoErr(t, err)
	th.AssertEquals(t, count, 1)
}

func TestListConsumersAllPages(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListConsumersSuccessfully(t)

	allPages, err := containers.ListConsumers(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0", nil).AllPages()
	th.AssertNoErr(t, err)
	actual, err := containers.ExtractConsumers(allPages)
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, ExpectedConsumersSlice, actual)
}

func TestCreateConsumer(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleCreateConsumerSuccessfully(t)

	createOpts := containers.CreateConsumerOpts{
		Name: "CONSUMER-LZILN1zq",
		URL:  "http://example.com",
	}

	actual, err := containers.CreateConsumer(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0", createOpts).Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, ExpectedCreatedConsumer, *actual)
}

func TestDeleteConsumer(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleDeleteConsumerSuccessfully(t)

	deleteOpts := containers.DeleteConsumerOpts{
		Name: "CONSUMER-LZILN1zq",
		URL:  "http://example.com",
	}

	actual, err := containers.DeleteConsumer(client.ServiceClient(), "dfdb88f3-4ddb-4525-9da6-066453caa9b0", deleteOpts).Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, FirstContainer, *actual)
}