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

import (
	"testing"

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

func TestListEC2Credentials(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListEC2CredentialsSuccessfully(t)

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

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

		th.CheckDeepEquals(t, ExpectedEC2CredentialsSlice, actual)

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

func TestListEC2CredentialsAllPages(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleListEC2CredentialsSuccessfully(t)

	allPages, err := ec2credentials.List(client.ServiceClient(), userID).AllPages()
	th.AssertNoErr(t, err)
	actual, err := ec2credentials.ExtractCredentials(allPages)
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ExpectedEC2CredentialsSlice, actual)
}

func TestGetEC2Credential(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleGetEC2CredentialSuccessfully(t)

	actual, err := ec2credentials.Get(client.ServiceClient(), userID, credentialID).Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, EC2Credential, *actual)
}

func TestCreateEC2Credential(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleCreateEC2CredentialSuccessfully(t)

	createOpts := ec2credentials.CreateOpts{
		TenantID: "6238dee2fec940a6bf31e49e9faf995a",
	}

	actual, err := ec2credentials.Create(client.ServiceClient(), userID, createOpts).Extract()
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, EC2Credential, *actual)
}

func TestDeleteEC2Credential(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleDeleteEC2CredentialSuccessfully(t)

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