1
1
package backups
2
2
3
3
import (
4
- "fmt"
5
- "net/http"
6
4
"testing"
7
5
8
- th "github.com/rackspace/gophercloud/testhelper"
9
- "github.com/rackspace/gophercloud/testhelper/client"
6
+ "github.com/rackspace/gophercloud/testhelper/fixture"
10
7
)
11
8
12
9
var singleBackup = `
@@ -31,27 +28,6 @@ var singleBackup = `
31
28
}
32
29
`
33
30
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
-
55
31
func HandleCreateSuccessfully (t * testing.T ) {
56
32
requestJSON := `
57
33
{
@@ -63,7 +39,7 @@ func HandleCreateSuccessfully(t *testing.T) {
63
39
}
64
40
`
65
41
66
- SetupHandler (t , "/backups" , "POST" , requestJSON , singleBackup , 202 )
42
+ fixture . SetupHandler (t , "/backups" , "POST" , requestJSON , singleBackup , 202 )
67
43
}
68
44
69
45
func HandleListSuccessfully (t * testing.T ) {
@@ -91,13 +67,13 @@ func HandleListSuccessfully(t *testing.T) {
91
67
}
92
68
`
93
69
94
- SetupHandler (t , "/backups" , "GET" , "" , responseJSON , 200 )
70
+ fixture . SetupHandler (t , "/backups" , "GET" , "" , responseJSON , 200 )
95
71
}
96
72
97
73
func HandleGetSuccessfully (t * testing.T , backupID string ) {
98
- SetupHandler (t , "/backups/" + backupID , "GET" , "" , singleBackup , 200 )
74
+ fixture . SetupHandler (t , "/backups/" + backupID , "GET" , "" , singleBackup , 200 )
99
75
}
100
76
101
77
func HandleDeleteSuccessfully (t * testing.T , backupID string ) {
102
- SetupHandler (t , "/backups/" + backupID , "DELETE" , "" , "" , 202 )
78
+ fixture . SetupHandler (t , "/backups/" + backupID , "DELETE" , "" , "" , 202 )
103
79
}
0 commit comments