github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dis/v2/streams/testing/fixtures.go (about) 1 package testing 2 3 import ( 4 "fmt" 5 "net/http" 6 "testing" 7 8 th "github.com/chnsz/golangsdk/testhelper" 9 "github.com/chnsz/golangsdk/testhelper/client" 10 ) 11 12 //mock response body string 13 var ( 14 mockListResponse = ` 15 { 16 "total_number": 2, 17 "stream_names": [ 18 "dis-ML2k", 19 "dis-XDPf" 20 ], 21 "stream_info_list": [ 22 { 23 "private": false, 24 "stream_id": "2kE3HAYBm5erI2sFtLb", 25 "stream_name": "dis-ML2k", 26 "create_time": 1632639303534, 27 "retention_period": 24, 28 "status": "RUNNING", 29 "stream_type": "ADVANCED", 30 "data_type": "CSV", 31 "partition_count": 1, 32 "tags": [ 33 { 34 "key": "key", 35 "value": "foo" 36 } 37 ], 38 "sys_tags": [ 39 { 40 "key": "_sys_enterprise_project_id", 41 "value": "0" 42 } 43 ], 44 "data_schema": "{\"type\":\"record\",\"name\":\"RecordName\",\"fields\":[{\"type\":\"string\",\"name\":\"name\"},{\"type\":\"int\",\"name\":\"age\"}]}", 45 "auto_scale_enabled": true, 46 "auto_scale_min_partition_count": 1, 47 "auto_scale_max_partition_count": 1 48 }, 49 { 50 "workSpaceId": "0970dd7a1300f5672ff2c003c60ae115", 51 "dayuInstanceId": "7f9529baa12645469ca5f89f4c4395f0", 52 "private": false, 53 "stream_id": "mz3V7jcVHcNDuaS3VpD", 54 "stream_name": "dis-XDPf", 55 "create_time": 1631344533496, 56 "retention_period": 24, 57 "status": "RUNNING", 58 "stream_type": "COMMON", 59 "data_type": "BLOB", 60 "partition_count": 1, 61 "tags": [], 62 "sys_tags": [ 63 { 64 "key": "_sys_enterprise_project_id", 65 "value": "0" 66 } 67 ], 68 "auto_scale_enabled": false, 69 "auto_scale_min_partition_count": 0, 70 "auto_scale_max_partition_count": 0 71 } 72 ], 73 "has_more_streams": false 74 } 75 ` 76 77 mockGetResponse = ` 78 { 79 "stream_id": "2kE3HAYBm5erI2sFtLb", 80 "stream_name": "dis-ML2k", 81 "create_time": 1632639303534, 82 "last_modified_time": 1632642001517, 83 "retention_period": 24, 84 "status": "RUNNING", 85 "stream_type": "ADVANCED", 86 "data_type": "CSV", 87 "data_schema": "{\"type\":\"record\",\"name\":\"RecordName\",\"fields\":[{\"type\":\"string\",\"name\":\"name\"},{\"type\":\"int\",\"name\":\"age\"}]}", 88 "csv_properties": { 89 "delimiter": ";" 90 }, 91 "writable_partition_count": 1, 92 "readable_partition_count": 2, 93 "partitions": [ 94 { 95 "status": "ACTIVE", 96 "partition_id": "shardId-0000000000", 97 "hash_range": "[0 : 9223372036854775807]", 98 "sequence_number_range": "[0 : 0]" 99 }, 100 { 101 "status": "DELETED", 102 "partition_id": "shardId-0000000001", 103 "hash_range": "[-1 : -1]", 104 "sequence_number_range": "[0 : 0]" 105 } 106 ], 107 "has_more_partitions": false, 108 "tags": [ 109 { 110 "key": "key", 111 "value": "foo" 112 } 113 ], 114 "sys_tags": [ 115 { 116 "key": "_sys_enterprise_project_id", 117 "value": "0" 118 } 119 ], 120 "auto_scale_enabled": true, 121 "auto_scale_min_partition_count": 1, 122 "auto_scale_max_partition_count": 1 123 } 124 ` 125 ) 126 127 func handleList(t *testing.T) { 128 th.Mux.HandleFunc("/streams", 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, mockListResponse) 134 }) 135 } 136 137 func handleGet(t *testing.T) { 138 th.Mux.HandleFunc("/streams/dis-ML2k", func(w http.ResponseWriter, r *http.Request) { 139 th.TestMethod(t, r, "GET") 140 th.TestHeader(t, r, "X-Auth-Token", client.TokenID) 141 w.Header().Add("Content-Type", "application/json") 142 w.WriteHeader(http.StatusOK) 143 _, _ = fmt.Fprint(w, mockGetResponse) 144 }) 145 }