github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/compute/v2/extensions/tenantnetworks/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/opentelekomcloud/gophertelekomcloud/openstack/compute/v2/extensions/tenantnetworks" 9 th "github.com/opentelekomcloud/gophertelekomcloud/testhelper" 10 "github.com/opentelekomcloud/gophertelekomcloud/testhelper/client" 11 ) 12 13 // ListOutput is a sample response to a List call. 14 const ListOutput = ` 15 { 16 "networks": [ 17 { 18 "cidr": "10.0.0.0/29", 19 "id": "20c8acc0-f747-4d71-a389-46d078ebf047", 20 "label": "mynet_0" 21 }, 22 { 23 "cidr": "10.0.0.10/29", 24 "id": "20c8acc0-f747-4d71-a389-46d078ebf000", 25 "label": "mynet_1" 26 } 27 ] 28 } 29 ` 30 31 // GetOutput is a sample response to a Get call. 32 const GetOutput = ` 33 { 34 "network": { 35 "cidr": "10.0.0.10/29", 36 "id": "20c8acc0-f747-4d71-a389-46d078ebf000", 37 "label": "mynet_1" 38 } 39 } 40 ` 41 42 // FirstNetwork is the first result in ListOutput. 43 var FirstNetwork = tenantnetworks.Network{ 44 CIDR: "10.0.0.0/29", 45 ID: "20c8acc0-f747-4d71-a389-46d078ebf047", 46 Name: "mynet_0", 47 } 48 49 // SecondNetwork is the second result in ListOutput. 50 var SecondNetwork = tenantnetworks.Network{ 51 CIDR: "10.0.0.10/29", 52 ID: "20c8acc0-f747-4d71-a389-46d078ebf000", 53 Name: "mynet_1", 54 } 55 56 // ExpectedNetworkSlice is the slice of results that should be parsed 57 // from ListOutput, in the expected order. 58 var ExpectedNetworkSlice = []tenantnetworks.Network{FirstNetwork, SecondNetwork} 59 60 // HandleListSuccessfully configures the test server to respond to a List request. 61 func HandleListSuccessfully(t *testing.T) { 62 th.Mux.HandleFunc("/os-tenant-networks", func(w http.ResponseWriter, r *http.Request) { 63 th.TestMethod(t, r, "GET") 64 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 65 66 w.Header().Add("Content-Type", "application/json") 67 _, _ = fmt.Fprint(w, ListOutput) 68 }) 69 } 70 71 // HandleGetSuccessfully configures the test server to respond to a Get request 72 // for an existing network. 73 func HandleGetSuccessfully(t *testing.T) { 74 th.Mux.HandleFunc("/os-tenant-networks/20c8acc0-f747-4d71-a389-46d078ebf000", func(w http.ResponseWriter, r *http.Request) { 75 th.TestMethod(t, r, "GET") 76 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 77 78 w.Header().Add("Content-Type", "application/json") 79 _, _ = fmt.Fprint(w, GetOutput) 80 }) 81 }