github.com/gophercloud/gophercloud@v1.11.0/openstack/identity/v3/domains/testing/fixtures_test.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/gophercloud/gophercloud/openstack/identity/v3/domains" 9 th "github.com/gophercloud/gophercloud/testhelper" 10 "github.com/gophercloud/gophercloud/testhelper/client" 11 ) 12 13 // ListAvailableOutput provides a single page of available domain results. 14 const ListAvailableOutput = ` 15 { 16 "domains": [ 17 { 18 "id": "52af04aec5f84182b06959d2775d2000", 19 "name": "TestDomain", 20 "description": "Testing domain", 21 "enabled": false, 22 "links": { 23 "self": "https://example.com/v3/domains/52af04aec5f84182b06959d2775d2000" 24 } 25 }, 26 { 27 "id": "a720688fb87f4575a4c000d818061eae", 28 "name": "ProdDomain", 29 "description": "Production domain", 30 "enabled": true, 31 "links": { 32 "self": "https://example.com/v3/domains/a720688fb87f4575a4c000d818061eae" 33 } 34 } 35 ], 36 "links": { 37 "next": null, 38 "self": "https://example.com/v3/auth/domains", 39 "previous": null 40 } 41 } 42 ` 43 44 // ListOutput provides a single page of Domain results. 45 const ListOutput = ` 46 { 47 "links": { 48 "next": null, 49 "previous": null, 50 "self": "http://example.com/identity/v3/domains" 51 }, 52 "domains": [ 53 { 54 "enabled": true, 55 "id": "2844b2a08be147a08ef58317d6471f1f", 56 "links": { 57 "self": "http://example.com/identity/v3/domains/2844b2a08be147a08ef58317d6471f1f" 58 }, 59 "name": "domain one", 60 "description": "some description" 61 }, 62 { 63 "enabled": true, 64 "id": "9fe1d3", 65 "links": { 66 "self": "https://example.com/identity/v3/domains/9fe1d3" 67 }, 68 "name": "domain two" 69 } 70 ] 71 } 72 ` 73 74 // GetOutput provides a Get result. 75 const GetOutput = ` 76 { 77 "domain": { 78 "enabled": true, 79 "id": "9fe1d3", 80 "links": { 81 "self": "https://example.com/identity/v3/domains/9fe1d3" 82 }, 83 "name": "domain two" 84 } 85 } 86 ` 87 88 // CreateRequest provides the input to a Create request. 89 const CreateRequest = ` 90 { 91 "domain": { 92 "name": "domain two" 93 } 94 } 95 ` 96 97 // UpdateRequest provides the input to as Update request. 98 const UpdateRequest = ` 99 { 100 "domain": { 101 "description": "Staging Domain" 102 } 103 } 104 ` 105 106 // UpdateOutput provides an update result. 107 const UpdateOutput = ` 108 { 109 "domain": { 110 "enabled": true, 111 "id": "9fe1d3", 112 "links": { 113 "self": "https://example.com/identity/v3/domains/9fe1d3" 114 }, 115 "name": "domain two", 116 "description": "Staging Domain" 117 } 118 } 119 ` 120 121 // ProdDomain is a domain fixture. 122 var ProdDomain = domains.Domain{ 123 Enabled: true, 124 ID: "a720688fb87f4575a4c000d818061eae", 125 Links: map[string]interface{}{ 126 "self": "https://example.com/v3/domains/a720688fb87f4575a4c000d818061eae", 127 }, 128 Name: "ProdDomain", 129 Description: "Production domain", 130 } 131 132 // TestDomain is a domain fixture. 133 var TestDomain = domains.Domain{ 134 Enabled: false, 135 ID: "52af04aec5f84182b06959d2775d2000", 136 Links: map[string]interface{}{ 137 "self": "https://example.com/v3/domains/52af04aec5f84182b06959d2775d2000", 138 }, 139 Name: "TestDomain", 140 Description: "Testing domain", 141 } 142 143 // FirstDomain is the first domain in the List request. 144 var FirstDomain = domains.Domain{ 145 Enabled: true, 146 ID: "2844b2a08be147a08ef58317d6471f1f", 147 Links: map[string]interface{}{ 148 "self": "http://example.com/identity/v3/domains/2844b2a08be147a08ef58317d6471f1f", 149 }, 150 Name: "domain one", 151 Description: "some description", 152 } 153 154 // SecondDomain is the second domain in the List request. 155 var SecondDomain = domains.Domain{ 156 Enabled: true, 157 ID: "9fe1d3", 158 Links: map[string]interface{}{ 159 "self": "https://example.com/identity/v3/domains/9fe1d3", 160 }, 161 Name: "domain two", 162 } 163 164 // SecondDomainUpdated is how SecondDomain should look after an Update. 165 var SecondDomainUpdated = domains.Domain{ 166 Enabled: true, 167 ID: "9fe1d3", 168 Links: map[string]interface{}{ 169 "self": "https://example.com/identity/v3/domains/9fe1d3", 170 }, 171 Name: "domain two", 172 Description: "Staging Domain", 173 } 174 175 // ExpectedAvailableDomainsSlice is the slice of domains expected to be returned 176 // from ListAvailableOutput. 177 var ExpectedAvailableDomainsSlice = []domains.Domain{TestDomain, ProdDomain} 178 179 // ExpectedDomainsSlice is the slice of domains expected to be returned from ListOutput. 180 var ExpectedDomainsSlice = []domains.Domain{FirstDomain, SecondDomain} 181 182 // HandleListAvailableDomainsSuccessfully creates an HTTP handler at `/auth/domains` 183 // on the test handler mux that responds with a list of two domains. 184 func HandleListAvailableDomainsSuccessfully(t *testing.T) { 185 th.Mux.HandleFunc("/auth/domains", func(w http.ResponseWriter, r *http.Request) { 186 th.TestMethod(t, r, "GET") 187 th.TestHeader(t, r, "Accept", "application/json") 188 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 189 190 w.Header().Set("Content-Type", "application/json") 191 w.WriteHeader(http.StatusOK) 192 fmt.Fprintf(w, ListAvailableOutput) 193 }) 194 } 195 196 // HandleListDomainsSuccessfully creates an HTTP handler at `/domains` on the 197 // test handler mux that responds with a list of two domains. 198 func HandleListDomainsSuccessfully(t *testing.T) { 199 th.Mux.HandleFunc("/domains", func(w http.ResponseWriter, r *http.Request) { 200 th.TestMethod(t, r, "GET") 201 th.TestHeader(t, r, "Accept", "application/json") 202 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 203 204 w.Header().Set("Content-Type", "application/json") 205 w.WriteHeader(http.StatusOK) 206 fmt.Fprintf(w, ListOutput) 207 }) 208 } 209 210 // HandleGetDomainSuccessfully creates an HTTP handler at `/domains` on the 211 // test handler mux that responds with a single domain. 212 func HandleGetDomainSuccessfully(t *testing.T) { 213 th.Mux.HandleFunc("/domains/9fe1d3", func(w http.ResponseWriter, r *http.Request) { 214 th.TestMethod(t, r, "GET") 215 th.TestHeader(t, r, "Accept", "application/json") 216 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 217 218 w.Header().Set("Content-Type", "application/json") 219 w.WriteHeader(http.StatusOK) 220 fmt.Fprintf(w, GetOutput) 221 }) 222 } 223 224 // HandleCreateDomainSuccessfully creates an HTTP handler at `/domains` on the 225 // test handler mux that tests domain creation. 226 func HandleCreateDomainSuccessfully(t *testing.T) { 227 th.Mux.HandleFunc("/domains", func(w http.ResponseWriter, r *http.Request) { 228 th.TestMethod(t, r, "POST") 229 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 230 th.TestJSONRequest(t, r, CreateRequest) 231 232 w.WriteHeader(http.StatusCreated) 233 fmt.Fprintf(w, GetOutput) 234 }) 235 } 236 237 // HandleDeleteDomainSuccessfully creates an HTTP handler at `/domains` on the 238 // test handler mux that tests domain deletion. 239 func HandleDeleteDomainSuccessfully(t *testing.T) { 240 th.Mux.HandleFunc("/domains/9fe1d3", func(w http.ResponseWriter, r *http.Request) { 241 th.TestMethod(t, r, "DELETE") 242 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 243 244 w.WriteHeader(http.StatusNoContent) 245 }) 246 } 247 248 // HandleUpdateDomainSuccessfully creates an HTTP handler at `/domains` on the 249 // test handler mux that tests domain update. 250 func HandleUpdateDomainSuccessfully(t *testing.T) { 251 th.Mux.HandleFunc("/domains/9fe1d3", func(w http.ResponseWriter, r *http.Request) { 252 th.TestMethod(t, r, "PATCH") 253 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 254 th.TestJSONRequest(t, r, UpdateRequest) 255 256 w.WriteHeader(http.StatusOK) 257 fmt.Fprintf(w, UpdateOutput) 258 }) 259 }