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