github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/autoscaling/v1/lifecyclehooks/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk/openstack/autoscaling/v1/lifecyclehooks" 9 th "github.com/huaweicloud/golangsdk/testhelper" 10 "github.com/huaweicloud/golangsdk/testhelper/client" 11 ) 12 13 const ( 14 expectedGetResponse = ` 15 { 16 "lifecycle_hook_name": "test-hook", 17 "default_result": "ABANDON", 18 "default_timeout": 3600, 19 "notification_topic_urn": "urn:smn:regionId:b53e5554fad0494d96206fb84296510b:gsh", 20 "notification_topic_name": "gsh", 21 "lifecycle_hook_type": "INSTANCE_LAUNCHING", 22 "notification_metadata": null, 23 "create_time": "2019-03-18T16:00:11Z" 24 }` 25 26 expectedUpdateResponse = ` 27 { 28 "lifecycle_hook_name": "test-hook", 29 "default_result": "CONTINUE", 30 "default_timeout": 3600, 31 "notification_topic_urn": "urn:smn:regionId:b53e5554fad0494d96206fb84296510b:gsh", 32 "notification_topic_name": "gsh", 33 "lifecycle_hook_type": "INSTANCE_LAUNCHING", 34 "notification_metadata": null, 35 "create_time": "2019-03-18T16:00:11Z" 36 }` 37 38 expectedListResponse = ` 39 { 40 "lifecycle_hooks": [ 41 { 42 "lifecycle_hook_name": "test-hook", 43 "default_result": "ABANDON", 44 "default_timeout": 3600, 45 "notification_topic_urn": "urn:smn:regionId:b53e5554fad0494d96206fb84296510b:gsh", 46 "notification_topic_name": "gsh", 47 "lifecycle_hook_type": "INSTANCE_LAUNCHING", 48 "notification_metadata": null, 49 "create_time": "2019-03-18T16:00:11Z" 50 } 51 ] 52 }` 53 ) 54 55 var ( 56 createOpts = lifecyclehooks.CreateOpts{ 57 Name: "test-hook", 58 Type: "INSTANCE_LAUNCHING", 59 DefaultResult: "ABANDON", 60 Timeout: 3600, 61 NotificationTopicURN: "urn:smn:regionId:b53e5554fad0494d96206fb84296510b:gsh", 62 } 63 64 expectedGetResponseData = &lifecyclehooks.Hook{ 65 Name: "test-hook", 66 DefaultResult: "ABANDON", 67 Type: "INSTANCE_LAUNCHING", 68 Timeout: 3600, 69 NotificationTopicURN: "urn:smn:regionId:b53e5554fad0494d96206fb84296510b:gsh", 70 NotificationTopicName: "gsh", 71 NotificationMetadata: "", 72 CreateTime: "2019-03-18T16:00:11Z", 73 } 74 75 expectedListResponseData = &[]lifecyclehooks.Hook{ 76 { 77 Name: "test-hook", 78 DefaultResult: "ABANDON", 79 Type: "INSTANCE_LAUNCHING", 80 Timeout: 3600, 81 NotificationTopicURN: "urn:smn:regionId:b53e5554fad0494d96206fb84296510b:gsh", 82 NotificationTopicName: "gsh", 83 NotificationMetadata: "", 84 CreateTime: "2019-03-18T16:00:11Z", 85 }, 86 } 87 88 updateOpts = lifecyclehooks.UpdateOpts{ 89 DefaultResult: "CONTINUE", 90 } 91 92 expectedUpdateResponseData = &lifecyclehooks.Hook{ 93 Name: "test-hook", 94 DefaultResult: "CONTINUE", 95 Type: "INSTANCE_LAUNCHING", 96 Timeout: 3600, 97 NotificationTopicURN: "urn:smn:regionId:b53e5554fad0494d96206fb84296510b:gsh", 98 NotificationTopicName: "gsh", 99 NotificationMetadata: "", 100 CreateTime: "2019-03-18T16:00:11Z", 101 } 102 ) 103 104 func handleLifeCycleHookCreate(t *testing.T) { 105 th.Mux.HandleFunc("/scaling_lifecycle_hook/50ed20b8-9853-4668-a71c-c8c15b5cb85f", 106 func(w http.ResponseWriter, r *http.Request) { 107 th.TestMethod(t, r, "POST") 108 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 109 w.Header().Add("Content-Type", "application/json") 110 w.WriteHeader(http.StatusOK) 111 _, _ = fmt.Fprint(w, expectedGetResponse) 112 }) 113 } 114 115 func handleLifeCycleHookGet(t *testing.T) { 116 th.Mux.HandleFunc("/scaling_lifecycle_hook/50ed20b8-9853-4668-a71c-c8c15b5cb85f/test-hook", 117 func(w http.ResponseWriter, r *http.Request) { 118 th.TestMethod(t, r, "GET") 119 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 120 w.Header().Add("Content-Type", "application/json") 121 w.WriteHeader(http.StatusOK) 122 _, _ = fmt.Fprint(w, expectedGetResponse) 123 }) 124 } 125 126 func handleLifeCycleHookList(t *testing.T) { 127 th.Mux.HandleFunc("/scaling_lifecycle_hook/50ed20b8-9853-4668-a71c-c8c15b5cb85f/list", 128 func(w http.ResponseWriter, r *http.Request) { 129 th.TestMethod(t, r, "GET") 130 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 131 w.Header().Add("Content-Type", "application/json") 132 w.WriteHeader(http.StatusOK) 133 _, _ = fmt.Fprint(w, expectedListResponse) 134 }) 135 } 136 137 func handleLifeCycleHookUpdate(t *testing.T) { 138 th.Mux.HandleFunc("/scaling_lifecycle_hook/50ed20b8-9853-4668-a71c-c8c15b5cb85f/test-hook", 139 func(w http.ResponseWriter, r *http.Request) { 140 th.TestMethod(t, r, "PUT") 141 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 142 w.Header().Add("Content-Type", "application/json") 143 w.WriteHeader(http.StatusOK) 144 _, _ = fmt.Fprint(w, expectedUpdateResponse) 145 }) 146 } 147 148 func handleLifeCycleHookDelete(t *testing.T) { 149 th.Mux.HandleFunc("/scaling_lifecycle_hook/50ed20b8-9853-4668-a71c-c8c15b5cb85f/test-hook", 150 func(w http.ResponseWriter, r *http.Request) { 151 th.TestMethod(t, r, "DELETE") 152 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 153 w.Header().Add("Content-Type", "application/json") 154 w.WriteHeader(http.StatusNoContent) 155 }) 156 }