github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/flavors/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 th "github.com/huaweicloud/golangsdk/testhelper" 9 fake "github.com/huaweicloud/golangsdk/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 // GetExtraSpecBody 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 // UpdatedExtraSpecBody provides an PUT result of a particular updated extra_spec for a flavor 30 const UpdatedExtraSpecBody = ` 31 { 32 "hw:cpu_policy": "CPU-POLICY-2" 33 } 34 ` 35 36 // ExtraSpecs is the expected extra_specs returned from GET on a flavor's extra_specs 37 var ExtraSpecs = map[string]string{ 38 "hw:cpu_policy": "CPU-POLICY", 39 "hw:cpu_thread_policy": "CPU-THREAD-POLICY", 40 } 41 42 // ExtraSpec is the expected extra_spec returned from GET on a flavor's extra_specs 43 var ExtraSpec = map[string]string{ 44 "hw:cpu_policy": "CPU-POLICY", 45 } 46 47 // UpdatedExtraSpec is the expected extra_spec returned from PUT on a flavor's extra_specs 48 var UpdatedExtraSpec = map[string]string{ 49 "hw:cpu_policy": "CPU-POLICY-2", 50 } 51 52 func HandleExtraSpecsListSuccessfully(t *testing.T) { 53 th.Mux.HandleFunc("/flavors/1/os-extra_specs", 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, ExtraSpecsGetBody) 61 }) 62 } 63 64 func HandleExtraSpecGetSuccessfully(t *testing.T) { 65 th.Mux.HandleFunc("/flavors/1/os-extra_specs/hw:cpu_policy", func(w http.ResponseWriter, r *http.Request) { 66 th.TestMethod(t, r, "GET") 67 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 68 th.TestHeader(t, r, "Accept", "application/json") 69 70 w.Header().Set("Content-Type", "application/json") 71 w.WriteHeader(http.StatusOK) 72 fmt.Fprintf(w, GetExtraSpecBody) 73 }) 74 } 75 76 func HandleExtraSpecsCreateSuccessfully(t *testing.T) { 77 th.Mux.HandleFunc("/flavors/1/os-extra_specs", func(w http.ResponseWriter, r *http.Request) { 78 th.TestMethod(t, r, "POST") 79 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 80 th.TestHeader(t, r, "Accept", "application/json") 81 th.TestJSONRequest(t, r, `{ 82 "extra_specs": { 83 "hw:cpu_policy": "CPU-POLICY", 84 "hw:cpu_thread_policy": "CPU-THREAD-POLICY" 85 } 86 }`) 87 88 w.Header().Set("Content-Type", "application/json") 89 w.WriteHeader(http.StatusOK) 90 fmt.Fprintf(w, ExtraSpecsGetBody) 91 }) 92 } 93 94 func HandleExtraSpecUpdateSuccessfully(t *testing.T) { 95 th.Mux.HandleFunc("/flavors/1/os-extra_specs/hw:cpu_policy", func(w http.ResponseWriter, r *http.Request) { 96 th.TestMethod(t, r, "PUT") 97 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 98 th.TestHeader(t, r, "Accept", "application/json") 99 th.TestJSONRequest(t, r, `{ 100 "hw:cpu_policy": "CPU-POLICY-2" 101 }`) 102 103 w.Header().Set("Content-Type", "application/json") 104 w.WriteHeader(http.StatusOK) 105 fmt.Fprintf(w, UpdatedExtraSpecBody) 106 }) 107 } 108 109 func HandleExtraSpecDeleteSuccessfully(t *testing.T) { 110 th.Mux.HandleFunc("/flavors/1/os-extra_specs/hw:cpu_policy", func(w http.ResponseWriter, r *http.Request) { 111 th.TestMethod(t, r, "DELETE") 112 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) 113 114 w.WriteHeader(http.StatusOK) 115 }) 116 }