github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/amphorae/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 "time" 8 9 "github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/amphorae" 10 th "github.com/gophercloud/gophercloud/testhelper" 11 "github.com/gophercloud/gophercloud/testhelper/client" 12 ) 13 14 // AmphoraeListBody contains the canned body of a amphora list response. 15 const AmphoraeListBody = ` 16 { 17 "amphorae": [ 18 { 19 "cached_zone": "nova", 20 "cert_busy": false, 21 "cert_expiration": "2020-08-08T23:44:31", 22 "compute_id": "667bb225-69aa-44b1-8908-694dc624c267", 23 "created_at": "2018-08-09T23:44:31", 24 "ha_ip": "10.0.0.6", 25 "ha_port_id": "35254b63-9361-4561-9b8f-2bb4e3be60e3", 26 "id": "45f40289-0551-483a-b089-47214bc2a8a4", 27 "image_id": "5d1aed06-2624-43f5-a413-9212263c3d53", 28 "lb_network_ip": "192.168.0.6", 29 "loadbalancer_id": "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9", 30 "role": "MASTER", 31 "status": "READY", 32 "updated_at": "2018-08-09T23:51:06", 33 "vrrp_id": 1, 34 "vrrp_interface": "eth1", 35 "vrrp_ip": "10.0.0.4", 36 "vrrp_port_id": "dcf0c8b5-6a08-4658-997d-eac97f2b9bbd", 37 "vrrp_priority": 100 38 }, 39 { 40 "cached_zone": "nova", 41 "cert_busy": false, 42 "cert_expiration": "2020-08-08T23:44:30", 43 "compute_id": "9cd0f9a2-fe12-42fc-a7e3-5b6fbbe20395", 44 "created_at": "2018-08-09T23:44:31", 45 "ha_ip": "10.0.0.6", 46 "ha_port_id": "35254b63-9361-4561-9b8f-2bb4e3be60e3", 47 "id": "7f890893-ced0-46ed-8697-33415d070e5a", 48 "image_id": "5d1aed06-2624-43f5-a413-9212263c3d53", 49 "lb_network_ip": "192.168.0.17", 50 "loadbalancer_id": "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9", 51 "role": "BACKUP", 52 "status": "READY", 53 "updated_at": "2018-08-09T23:51:06", 54 "vrrp_id": 1, 55 "vrrp_interface": "eth1", 56 "vrrp_ip": "10.0.0.21", 57 "vrrp_port_id": "13c88c77-207d-4f85-8f7a-84344592e367", 58 "vrrp_priority": 90 59 } 60 ], 61 "amphorae_links": [] 62 } 63 ` 64 65 const SingleAmphoraBody = ` 66 { 67 "amphora": { 68 "cached_zone": "nova", 69 "cert_busy": false, 70 "cert_expiration": "2020-08-08T23:44:31", 71 "compute_id": "667bb225-69aa-44b1-8908-694dc624c267", 72 "created_at": "2018-08-09T23:44:31", 73 "ha_ip": "10.0.0.6", 74 "ha_port_id": "35254b63-9361-4561-9b8f-2bb4e3be60e3", 75 "id": "45f40289-0551-483a-b089-47214bc2a8a4", 76 "image_id": "5d1aed06-2624-43f5-a413-9212263c3d53", 77 "lb_network_ip": "192.168.0.6", 78 "loadbalancer_id": "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9", 79 "role": "MASTER", 80 "status": "READY", 81 "updated_at": "2018-08-09T23:51:06", 82 "vrrp_id": 1, 83 "vrrp_interface": "eth1", 84 "vrrp_ip": "10.0.0.4", 85 "vrrp_port_id": "dcf0c8b5-6a08-4658-997d-eac97f2b9bbd", 86 "vrrp_priority": 100 87 } 88 } 89 ` 90 91 // FirstAmphora is the first resource in the List request. 92 var FirstAmphora = amphorae.Amphora{ 93 CachedZone: "nova", 94 CertBusy: false, 95 CertExpiration: time.Date(2020, 8, 8, 23, 44, 31, 0, time.UTC), 96 ComputeID: "667bb225-69aa-44b1-8908-694dc624c267", 97 CreatedAt: time.Date(2018, 8, 9, 23, 44, 31, 0, time.UTC), 98 HAIP: "10.0.0.6", 99 HAPortID: "35254b63-9361-4561-9b8f-2bb4e3be60e3", 100 ID: "45f40289-0551-483a-b089-47214bc2a8a4", 101 ImageID: "5d1aed06-2624-43f5-a413-9212263c3d53", 102 LBNetworkIP: "192.168.0.6", 103 LoadbalancerID: "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9", 104 Role: "MASTER", 105 Status: "READY", 106 UpdatedAt: time.Date(2018, 8, 9, 23, 51, 6, 0, time.UTC), 107 VRRPID: 1, 108 VRRPInterface: "eth1", 109 VRRPIP: "10.0.0.4", 110 VRRPPortID: "dcf0c8b5-6a08-4658-997d-eac97f2b9bbd", 111 VRRPPriority: 100, 112 } 113 114 // SecondAmphora is the second resource in the List request. 115 var SecondAmphora = amphorae.Amphora{ 116 CachedZone: "nova", 117 CertBusy: false, 118 CertExpiration: time.Date(2020, 8, 8, 23, 44, 30, 0, time.UTC), 119 ComputeID: "9cd0f9a2-fe12-42fc-a7e3-5b6fbbe20395", 120 CreatedAt: time.Date(2018, 8, 9, 23, 44, 31, 0, time.UTC), 121 HAIP: "10.0.0.6", 122 HAPortID: "35254b63-9361-4561-9b8f-2bb4e3be60e3", 123 ID: "7f890893-ced0-46ed-8697-33415d070e5a", 124 ImageID: "5d1aed06-2624-43f5-a413-9212263c3d53", 125 LBNetworkIP: "192.168.0.17", 126 LoadbalancerID: "882f2a9d-9d53-4bd0-b0e9-08e9d0de11f9", 127 Role: "BACKUP", 128 Status: "READY", 129 UpdatedAt: time.Date(2018, 8, 9, 23, 51, 6, 0, time.UTC), 130 VRRPID: 1, 131 VRRPInterface: "eth1", 132 VRRPIP: "10.0.0.21", 133 VRRPPortID: "13c88c77-207d-4f85-8f7a-84344592e367", 134 VRRPPriority: 90, 135 } 136 137 // ExpectedAmphoraeSlice is the slice of amphorae expected to be returned from ListResponse. 138 var ExpectedAmphoraeSlice = []amphorae.Amphora{FirstAmphora, SecondAmphora} 139 140 // HandleAmphoraListSuccessfully sets up the test server to respond to a amphorae List request. 141 func HandleAmphoraListSuccessfully(t *testing.T) { 142 th.Mux.HandleFunc("/v2.0/octavia/amphorae", func(w http.ResponseWriter, r *http.Request) { 143 th.TestMethod(t, r, "GET") 144 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 145 146 w.Header().Add("Content-Type", "application/json") 147 r.ParseForm() 148 marker := r.Form.Get("marker") 149 switch marker { 150 case "": 151 fmt.Fprintf(w, AmphoraeListBody) 152 case "7f890893-ced0-46ed-8697-33415d070e5a": 153 fmt.Fprintf(w, `{ "amphorae": [] }`) 154 default: 155 t.Fatalf("/v2.0/octavia/amphorae invoked with unexpected marker=[%s]", marker) 156 } 157 }) 158 } 159 160 // HandleAmphoraGetSuccessfully sets up the test server to respond to am amphora Get request. 161 func HandleAmphoraGetSuccessfully(t *testing.T) { 162 th.Mux.HandleFunc("/v2.0/octavia/amphorae/45f40289-0551-483a-b089-47214bc2a8a4", func(w http.ResponseWriter, r *http.Request) { 163 th.TestMethod(t, r, "GET") 164 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 165 th.TestHeader(t, r, "Accept", "application/json") 166 167 fmt.Fprintf(w, SingleAmphoraBody) 168 }) 169 } 170 171 // HandleAmphoraFailoverSuccessfully sets up the test server to respond to an amphora failover request. 172 func HandleAmphoraFailoverSuccessfully(t *testing.T) { 173 th.Mux.HandleFunc("/v2.0/octavia/amphorae/36e08a3e-a78f-4b40-a229-1e7e23eee1ab/failover", func(w http.ResponseWriter, r *http.Request) { 174 th.TestMethod(t, r, "PUT") 175 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 176 177 w.WriteHeader(http.StatusAccepted) 178 }) 179 }