Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit be00824

Browse files
author
Jamie Hannaford
committed
Use new helper
1 parent ed7f453 commit be00824

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

rackspace/db/v1/backups/fixtures.go

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package backups
22

33
import (
4-
"fmt"
5-
"net/http"
64
"testing"
75

8-
th "github.com/rackspace/gophercloud/testhelper"
9-
"github.com/rackspace/gophercloud/testhelper/client"
6+
"github.com/rackspace/gophercloud/testhelper/fixture"
107
)
118

129
var singleBackup = `
@@ -31,27 +28,6 @@ var singleBackup = `
3128
}
3229
`
3330

34-
func SetupHandler(t *testing.T, url, method, requestBody, responseBody string, status int) {
35-
th.Mux.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) {
36-
th.TestMethod(t, r, method)
37-
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
38-
39-
if requestBody != "" {
40-
th.TestJSONRequest(t, r, requestBody)
41-
}
42-
43-
if responseBody != "" {
44-
w.Header().Add("Content-Type", "application/json")
45-
}
46-
47-
w.WriteHeader(status)
48-
49-
if responseBody != "" {
50-
fmt.Fprintf(w, responseBody)
51-
}
52-
})
53-
}
54-
5531
func HandleCreateSuccessfully(t *testing.T) {
5632
requestJSON := `
5733
{
@@ -63,7 +39,7 @@ func HandleCreateSuccessfully(t *testing.T) {
6339
}
6440
`
6541

66-
SetupHandler(t, "/backups", "POST", requestJSON, singleBackup, 202)
42+
fixture.SetupHandler(t, "/backups", "POST", requestJSON, singleBackup, 202)
6743
}
6844

6945
func HandleListSuccessfully(t *testing.T) {
@@ -91,13 +67,13 @@ func HandleListSuccessfully(t *testing.T) {
9167
}
9268
`
9369

94-
SetupHandler(t, "/backups", "GET", "", responseJSON, 200)
70+
fixture.SetupHandler(t, "/backups", "GET", "", responseJSON, 200)
9571
}
9672

9773
func HandleGetSuccessfully(t *testing.T, backupID string) {
98-
SetupHandler(t, "/backups/"+backupID, "GET", "", singleBackup, 200)
74+
fixture.SetupHandler(t, "/backups/"+backupID, "GET", "", singleBackup, 200)
9975
}
10076

10177
func HandleDeleteSuccessfully(t *testing.T, backupID string) {
102-
SetupHandler(t, "/backups/"+backupID, "DELETE", "", "", 202)
78+
fixture.SetupHandler(t, "/backups/"+backupID, "DELETE", "", "", 202)
10379
}

0 commit comments

Comments
 (0)