File: fixtures.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 0.0~git20180917.45f1c769-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,768 kB
  • sloc: sh: 98; makefile: 14
file content (118 lines) | stat: -rw-r--r-- 3,547 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package testing

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

	"github.com/gophercloud/gophercloud/openstack/service/vN/resources"
	th "github.com/gophercloud/gophercloud/testhelper"
	"github.com/gophercloud/gophercloud/testhelper/client"
)

// ListResult provides a single page of RESOURCE results.
const ListResult = `
{
}
`

// GetResult provides a Get result.
const GetResult = `
{
}
`

// CreateRequest provides the input to a Create request.
const CreateRequest = `
{
}
`

// UpdateRequest provides the input to as Update request.
const UpdateRequest = `
{
}
`

// UpdateResult provides an update result.
const UpdateResult = `
{
}
`

// FirstResource is the first resource in the List request.
var FirstResource = resources.Resource{}

// SecondResource is the second resource in the List request.
var SecondResource = resources.Resource{}

// SecondResourceUpdated is how SecondResource should look after an Update.
var SecondResourceUpdated = resources.Resource{}

// ExpectedResourcesSlice is the slice of resources expected to be returned from ListResult.
var ExpectedResourcesSlice = []resources.Resource{FirstResource, SecondResource}

// HandleListResourceSuccessfully creates an HTTP handler at `/resources` on the
// test handler mux that responds with a list of two resources.
func HandleListResourceSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/resources", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "Accept", "application/json")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, ListResult)
	})
}

// HandleGetResourceSuccessfully creates an HTTP handler at `/resources` on the
// test handler mux that responds with a single resource.
func HandleGetResourceSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/resources/9fe1d3", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "GET")
		th.TestHeader(t, r, "Accept", "application/json")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, GetResult)
	})
}

// HandleCreateResourceSuccessfully creates an HTTP handler at `/resources` on the
// test handler mux that tests resource creation.
func HandleCreateResourceSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/resources", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "POST")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
		th.TestJSONRequest(t, r, CreateRequest)

		w.WriteHeader(http.StatusCreated)
		fmt.Fprintf(w, GetResult)
	})
}

// HandleDeleteResourceSuccessfully creates an HTTP handler at `/resources` on the
// test handler mux that tests resource deletion.
func HandleDeleteResourceSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/resources/9fe1d3", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "DELETE")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)

		w.WriteHeader(http.StatusNoContent)
	})
}

// HandleUpdateResourceSuccessfully creates an HTTP handler at `/resources` on the
// test handler mux that tests resource update.
func HandleUpdateResourceSuccessfully(t *testing.T) {
	th.Mux.HandleFunc("/resources/9fe1d3", func(w http.ResponseWriter, r *http.Request) {
		th.TestMethod(t, r, "PATCH")
		th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
		th.TestJSONRequest(t, r, UpdateRequest)

		w.WriteHeader(http.StatusOK)
		fmt.Fprintf(w, UpdateResult)
	})
}