github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/fgs/v2/trigger/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 "github.com/huaweicloud/golangsdk/openstack/fgs/v2/trigger" 9 th "github.com/huaweicloud/golangsdk/testhelper" 10 "github.com/huaweicloud/golangsdk/testhelper/client" 11 ) 12 13 const ( 14 expectedGetResponse = ` 15 { 16 "trigger_id": "971f9cff-5d29-42da-ba36-e4e2b9d26664", 17 "trigger_type_code": "TIMER", 18 "trigger_status": "ACTIVE", 19 "event_data": { 20 "name": "test", 21 "schedule": "1d", 22 "schedule_type": "Rate" 23 }, 24 "last_updated_time": "2021-08-11T17:03:20+08:00", 25 "created_time": "2021-08-11T17:03:20+08:00" 26 }` 27 28 expectedListResponse = ` 29 [ 30 { 31 "trigger_id": "971f9cff-5d29-42da-ba36-e4e2b9d26664", 32 "trigger_type_code": "TIMER", 33 "trigger_status": "ACTIVE", 34 "event_data": { 35 "name": "test", 36 "schedule": "1d", 37 "schedule_type": "Rate" 38 }, 39 "last_updated_time": "2021-08-11T17:03:20+08:00", 40 "created_time": "2021-08-11T17:03:20+08:00" 41 } 42 ]` 43 ) 44 45 var ( 46 createOpts = &trigger.CreateOpts{ 47 TriggerTypeCode: "TIMER", 48 TriggerStatus: "ACTIVE", 49 EventTypeCode: "MessageCreated", 50 EventData: map[string]interface{}{ 51 "name": "test", 52 "schedule": "1d", 53 "schedule_type": "Rate", 54 }, 55 } 56 57 expectedGetResponseData = &trigger.Trigger{ 58 CreatedTime: "2021-08-11T17:03:20+08:00", 59 TriggerId: "971f9cff-5d29-42da-ba36-e4e2b9d26664", 60 TriggerTypeCode: "TIMER", 61 EventData: map[string]interface{}{ 62 "name": "test", 63 "schedule": "1d", 64 "schedule_type": "Rate", 65 }, 66 Status: "ACTIVE", 67 LastUpdatedTime: "2021-08-11T17:03:20+08:00", 68 } 69 70 expectedListResponseData = []trigger.Trigger{ 71 { 72 CreatedTime: "2021-08-11T17:03:20+08:00", 73 TriggerId: "971f9cff-5d29-42da-ba36-e4e2b9d26664", 74 TriggerTypeCode: "TIMER", 75 EventData: map[string]interface{}{ 76 "name": "test", 77 "schedule": "1d", 78 "schedule_type": "Rate", 79 }, 80 Status: "ACTIVE", 81 LastUpdatedTime: "2021-08-11T17:03:20+08:00", 82 }, 83 } 84 85 updateOpts = trigger.UpdateOpts{ 86 TriggerStatus: "ACTIVE", 87 } 88 ) 89 90 func handleV2TriggerCreate(t *testing.T) { 91 th.Mux.HandleFunc("/fgs/triggers/urn:fss:cn-north-4:0721565481a5d123f6e6c66a2115215a:function:default:test", 92 func(w http.ResponseWriter, r *http.Request) { 93 th.TestMethod(t, r, "POST") 94 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 95 w.Header().Add("Content-Type", "application/json") 96 w.WriteHeader(http.StatusCreated) 97 _, _ = fmt.Fprint(w, expectedGetResponse) 98 }) 99 } 100 101 func handleV2TriggerGet(t *testing.T) { 102 th.Mux.HandleFunc("/fgs/triggers/urn:fss:cn-north-4:0721565481a5d123f6e6c66a2115215a:function:default:test"+ 103 "/TIMER/971f9cff-5d29-42da-ba36-e4e2b9d26664", func(w http.ResponseWriter, r *http.Request) { 104 th.TestMethod(t, r, "GET") 105 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 106 w.Header().Add("Content-Type", "application/json") 107 w.WriteHeader(http.StatusOK) 108 _, _ = fmt.Fprint(w, expectedGetResponse) 109 }) 110 } 111 112 func handleV2TriggerList(t *testing.T) { 113 th.Mux.HandleFunc("/fgs/triggers/urn:fss:cn-north-4:0721565481a5d123f6e6c66a2115215a:function:default:test", 114 func(w http.ResponseWriter, r *http.Request) { 115 th.TestMethod(t, r, "GET") 116 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 117 w.Header().Add("Content-Type", "application/json") 118 w.WriteHeader(http.StatusOK) 119 _, _ = fmt.Fprint(w, expectedListResponse) 120 }) 121 } 122 123 func handleV2TriggerUpdate(t *testing.T) { 124 th.Mux.HandleFunc("/fgs/triggers/urn:fss:cn-north-4:0721565481a5d123f6e6c66a2115215a:function:default:test"+ 125 "/TIMER/971f9cff-5d29-42da-ba36-e4e2b9d26664", func(w http.ResponseWriter, r *http.Request) { 126 th.TestMethod(t, r, "PUT") 127 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 128 w.Header().Add("Content-Type", "application/json") 129 w.WriteHeader(http.StatusOK) 130 _, _ = fmt.Fprint(w, expectedGetResponse) 131 }) 132 } 133 134 func handleV2TriggerDelete(t *testing.T) { 135 th.Mux.HandleFunc("/fgs/triggers/urn:fss:cn-north-4:0721565481a5d123f6e6c66a2115215a:function:default:test"+ 136 "/TIMER/971f9cff-5d29-42da-ba36-e4e2b9d26664", func(w http.ResponseWriter, r *http.Request) { 137 th.TestMethod(t, r, "DELETE") 138 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 139 w.Header().Add("Content-Type", "application/json") 140 w.WriteHeader(http.StatusNoContent) 141 }) 142 }