|
@@ -53,6 +53,11 @@ type ObjectDetectResponse struct {
|
|
// Box Box `json:"box,omitempty"`
|
|
// Box Box `json:"box,omitempty"`
|
|
//}
|
|
//}
|
|
|
|
|
|
|
|
+type EncodedRequest struct {
|
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
|
+ Size int `json:"size,omitempty"`
|
|
|
|
+}
|
|
|
|
+
|
|
func TestRestService(t *testing.T) {
|
|
func TestRestService(t *testing.T) {
|
|
// mock server, the port is set in the sample.json
|
|
// mock server, the port is set in the sample.json
|
|
l, err := net.Listen("tcp", "127.0.0.1:51234")
|
|
l, err := net.Listen("tcp", "127.0.0.1:51234")
|
|
@@ -81,6 +86,9 @@ func TestRestService(t *testing.T) {
|
|
if err != nil {
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
}
|
|
}
|
|
|
|
+ if req.Image == "" {
|
|
|
|
+ http.Error(w, "image is not found", http.StatusBadRequest)
|
|
|
|
+ }
|
|
out = &ObjectDetectResponse{
|
|
out = &ObjectDetectResponse{
|
|
Info: req.Command,
|
|
Info: req.Command,
|
|
Code: 200,
|
|
Code: 200,
|
|
@@ -93,6 +101,14 @@ func TestRestService(t *testing.T) {
|
|
count++
|
|
count++
|
|
io.WriteString(w, fmt.Sprintf("%v", r))
|
|
io.WriteString(w, fmt.Sprintf("%v", r))
|
|
return
|
|
return
|
|
|
|
+ case "/RestEncodedJson":
|
|
|
|
+ req := &EncodedRequest{}
|
|
|
|
+ err := json.NewDecoder(r.Body).Decode(req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ http.Error(w, err.Error(), http.StatusBadRequest)
|
|
|
|
+ }
|
|
|
|
+ io.WriteString(w, req.Name)
|
|
|
|
+ return
|
|
default:
|
|
default:
|
|
http.Error(w, "path not supported", http.StatusBadRequest)
|
|
http.Error(w, "path not supported", http.StatusBadRequest)
|
|
}
|
|
}
|
|
@@ -246,6 +262,30 @@ func TestRestService(t *testing.T) {
|
|
"sink_mockSink_0_records_in_total": int64(3),
|
|
"sink_mockSink_0_records_in_total": int64(3),
|
|
"sink_mockSink_0_records_out_total": int64(3),
|
|
"sink_mockSink_0_records_out_total": int64(3),
|
|
},
|
|
},
|
|
|
|
+ }, {
|
|
|
|
+ Name: `TestRestRule5`,
|
|
|
|
+ Sql: `SELECT restEncodedJson(encoded_json) as name FROM commands`,
|
|
|
|
+ R: [][]map[string]interface{}{
|
|
|
|
+ {{
|
|
|
|
+ "name": "name1",
|
|
|
|
+ }},
|
|
|
|
+ {{
|
|
|
|
+ "name": "name2",
|
|
|
|
+ }},
|
|
|
|
+ {{
|
|
|
|
+ "name": "name3",
|
|
|
|
+ }},
|
|
|
|
+ },
|
|
|
|
+ M: map[string]interface{}{
|
|
|
|
+ "op_2_project_0_exceptions_total": int64(0),
|
|
|
|
+ "op_2_project_0_process_latency_us": int64(0),
|
|
|
|
+ "op_2_project_0_records_in_total": int64(3),
|
|
|
|
+ "op_2_project_0_records_out_total": int64(3),
|
|
|
|
+
|
|
|
|
+ "sink_mockSink_0_exceptions_total": int64(0),
|
|
|
|
+ "sink_mockSink_0_records_in_total": int64(3),
|
|
|
|
+ "sink_mockSink_0_records_out_total": int64(3),
|
|
|
|
+ },
|
|
},
|
|
},
|
|
}
|
|
}
|
|
topotest.HandleStream(true, streamList, t)
|
|
topotest.HandleStream(true, streamList, t)
|