|
| 1 | +package testing |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "net/http" |
| 6 | + "testing" |
| 7 | + |
| 8 | + th "github.com/gophercloud/gophercloud/testhelper" |
| 9 | + fake "github.com/gophercloud/gophercloud/testhelper/client" |
| 10 | +) |
| 11 | + |
| 12 | +// ExtraSpecsGetBody provides a GET result of the extra_specs for a flavor |
| 13 | +const ExtraSpecsGetBody = ` |
| 14 | +{ |
| 15 | + "extra_specs" : { |
| 16 | + "hw:cpu_policy": "CPU-POLICY", |
| 17 | + "hw:cpu_thread_policy": "CPU-THREAD-POLICY" |
| 18 | + } |
| 19 | +} |
| 20 | +` |
| 21 | + |
| 22 | +// ExtraSpecGetBody provides a GET result of a particular extra_spec for a flavor |
| 23 | +const GetExtraSpecBody = ` |
| 24 | +{ |
| 25 | + "hw:cpu_policy": "CPU-POLICY" |
| 26 | +} |
| 27 | +` |
| 28 | + |
| 29 | +// ExtraSpecs is the expected extra_specs returned from GET on a flavor's extra_specs |
| 30 | +var ExtraSpecs = map[string]string{ |
| 31 | + "hw:cpu_policy": "CPU-POLICY", |
| 32 | + "hw:cpu_thread_policy": "CPU-THREAD-POLICY", |
| 33 | +} |
| 34 | + |
| 35 | +// ExtraSpec is the expected extra_spec returned from GET on a flavor's extra_specs |
| 36 | +var ExtraSpec = map[string]string{ |
| 37 | + "hw:cpu_policy": "CPU-POLICY", |
| 38 | +} |
| 39 | + |
| 40 | +func HandleExtraSpecsListSuccessfully(t *testing.T) { |
| 41 | + th.Mux.HandleFunc("/flavors/1/os-extra_specs", func(w http.ResponseWriter, r *http.Request) { |
| 42 | + th.TestMethod(t, r, "GET") |
| 43 | + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 44 | + th.TestHeader(t, r, "Accept", "application/json") |
| 45 | + |
| 46 | + w.Header().Set("Content-Type", "application/json") |
| 47 | + w.WriteHeader(http.StatusOK) |
| 48 | + fmt.Fprintf(w, ExtraSpecsGetBody) |
| 49 | + }) |
| 50 | +} |
| 51 | + |
| 52 | +func HandleExtraSpecGetSuccessfully(t *testing.T) { |
| 53 | + th.Mux.HandleFunc("/flavors/1/os-extra_specs/hw:cpu_policy", func(w http.ResponseWriter, r *http.Request) { |
| 54 | + th.TestMethod(t, r, "GET") |
| 55 | + th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 56 | + th.TestHeader(t, r, "Accept", "application/json") |
| 57 | + |
| 58 | + w.Header().Set("Content-Type", "application/json") |
| 59 | + w.WriteHeader(http.StatusOK) |
| 60 | + fmt.Fprintf(w, GetExtraSpecBody) |
| 61 | + }) |
| 62 | +} |
0 commit comments