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 (53 lines) | stat: -rw-r--r-- 1,359 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
package testing

import (
	"testing"

	"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/providers"
	fake "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/testhelper"
	"github.com/gophercloud/gophercloud/pagination"
	th "github.com/gophercloud/gophercloud/testhelper"
)

func TestListProviders(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleProviderListSuccessfully(t)

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

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

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

		return true, nil
	})

	th.AssertNoErr(t, err)

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

func TestListAllProviders(t *testing.T) {
	th.SetupHTTP()
	defer th.TeardownHTTP()
	HandleProviderListSuccessfully(t)

	allPages, err := providers.List(fake.ServiceClient(), providers.ListOpts{}).AllPages()
	th.AssertNoErr(t, err)
	actual, err := providers.ExtractProviders(allPages)
	th.AssertNoErr(t, err)
	th.CheckDeepEquals(t, ProviderAmphora, actual[0])
	th.CheckDeepEquals(t, ProviderOVN, actual[1])
}