File: requests_test.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (53 lines) | stat: -rw-r--r-- 1,489 bytes parent folder | download
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 (
	"fmt"
	"net/http"
	"testing"
	"time"

	"github.com/gophercloud/gophercloud/openstack/sharedfilesystems/v2/shareaccessrules"
	th "github.com/gophercloud/gophercloud/testhelper"
	"github.com/gophercloud/gophercloud/testhelper/client"
	fake "github.com/gophercloud/gophercloud/testhelper/client"
)

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

	MockGetResponse(t)

	resp := shareaccessrules.Get(client.ServiceClient(), "507bf114-36f2-4f56-8cf4-857985ca87c1")
	th.AssertNoErr(t, resp.Err)

	accessRule, err := resp.Extract()
	th.AssertNoErr(t, err)

	th.AssertDeepEquals(t, &shareaccessrules.ShareAccess{
		ShareID:     "fb213952-2352-41b4-ad7b-2c4c69d13eef",
		CreatedAt:   time.Date(2018, 7, 17, 2, 1, 4, 0, time.UTC),
		UpdatedAt:   time.Date(2018, 7, 17, 2, 1, 4, 0, time.UTC),
		AccessType:  "cert",
		AccessTo:    "example.com",
		AccessKey:   "",
		State:       "error",
		AccessLevel: "rw",
		ID:          "507bf114-36f2-4f56-8cf4-857985ca87c1",
		Metadata: map[string]interface{}{
			"key1": "value1",
			"key2": "value2",
		},
	}, accessRule)
}

func MockListResponse(t *testing.T) {
	th.Mux.HandleFunc(shareAccessRulesEndpoint, func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
		th.TestHeader(t, r, "Accept", "application/json")
		w.Header().Add("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, listResponse)
	})
}