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 (99 lines) | stat: -rw-r--r-- 2,935 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
99
package testing

import (
	"testing"

	"github.com/gophercloud/gophercloud/openstack/identity/v3/credentials"
	"github.com/gophercloud/gophercloud/pagination"
	th "github.com/gophercloud/gophercloud/testhelper"
	"github.com/gophercloud/gophercloud/testhelper/client"
)

func TestListCredentials(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListCredentialsSuccessfully(t)

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

		actual, err := credentials.ExtractCredentials(page)
		th.AssertNoErr(t, err)

		th.CheckDeepEquals(t, ExpectedCredentialsSlice, actual)

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

func TestListCredentialsAllPages(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListCredentialsSuccessfully(t)

	allPages, err := credentials.List(client.ServiceClient(), nil).AllPages()
	th.AssertNoErr(t, err)
	actual, err := credentials.ExtractCredentials(allPages)
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ExpectedCredentialsSlice, actual)
	th.AssertDeepEquals(t, ExpectedCredentialsSlice[0].Blob, "{\"access\":\"181920\",\"secret\":\"secretKey\"}")
	th.AssertDeepEquals(t, ExpectedCredentialsSlice[1].Blob, "{\"access\":\"7da79ff0aa364e1396f067e352b9b79a\",\"secret\":\"7a18d68ba8834b799d396f3ff6f1e98c\"}")
}

func TestGetCredential(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleGetCredentialSuccessfully(t)

	actual, err := credentials.Get(client.ServiceClient(), credentialID).Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, Credential, *actual)
}

func TestCreateCredential(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleCreateCredentialSuccessfully(t)

	createOpts := credentials.CreateOpts{
		ProjectID: projectID,
		Type:      "ec2",
		UserID:    userID,
		Blob:      "{\"access\":\"181920\",\"secret\":\"secretKey\"}",
	}

	CredentialResponse := Credential

	actual, err := credentials.Create(client.ServiceClient(), createOpts).Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, CredentialResponse, *actual)
}

func TestDeleteCredential(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleDeleteCredentialSuccessfully(t)

	res := credentials.Delete(client.ServiceClient(), credentialID)
	th.AssertNoErr(t, res.Err)
}

func TestUpdateCredential(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleUpdateCredentialSuccessfully(t)

	updateOpts := credentials.UpdateOpts{
		ProjectID: "731fc6f265cd486d900f16e84c5cb594",
		Type:      "ec2",
		UserID:    "bb5476fd12884539b41d5a88f838d773",
		Blob:      "{\"access\":\"181920\",\"secret\":\"secretKey\"}",
	}

	actual, err := credentials.Update(client.ServiceClient(), "2441494e52ab6d594a34d74586075cb299489bdd1e9389e3ab06467a4f460609", updateOpts).Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, SecondCredentialUpdated, *actual)
}