File: requests_test.go

package info (click to toggle)
golang-github-gophercloud-utils 0.0~git20231010.80377ec-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 816 kB
  • sloc: sh: 20; makefile: 7
file content (63 lines) | stat: -rw-r--r-- 1,616 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
package testing

import (
	"fmt"
	"net/http"
	"testing"

	th "github.com/gophercloud/gophercloud/testhelper"
	"github.com/gophercloud/utils/gnocchi/metric/v1/status"
	fake "github.com/gophercloud/utils/gnocchi/testhelper/client"
)

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

	th.Mux.HandleFunc("/v1/status", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, StatusGetWithDetailsResult)
	})

	details := true

	getOpts := status.GetOpts{
		Details: &details,
	}

	s, err := status.Get(fake.ServiceClient(), getOpts).Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, s.Metricd, GetStatusWithDetailsExpected.Metricd)
	th.AssertDeepEquals(t, s.Storage, GetStatusWithDetailsExpected.Storage)
}

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

	th.Mux.HandleFunc("/v1/status", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)

		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)

		fmt.Fprintf(w, StatusGetWithoutDetailsResult)
	})

	details := false

	getOpts := status.GetOpts{
		Details: &details,
	}

	s, err := status.Get(fake.ServiceClient(), getOpts).Extract()
	th.AssertNoErr(t, err)
	th.AssertDeepEquals(t, s.Metricd, GetStatusWithoutDetailsExpected.Metricd)
	th.AssertDeepEquals(t, s.Storage, GetStatusWithoutDetailsExpected.Storage)
}