@@ -131,34 +131,35 @@ func TestJsonFormat(t *testing.T) {
131
131
binAnnoJSON := createBinAnno ("http.status_code" , "200" , endpJSON )
132
132
spanJSON := createSpan ("bar" , "1234567891234565" , "1234567891234567" , "1234567891234568" , 156 , 15145 , false ,
133
133
annoJSON , binAnnoJSON )
134
-
135
134
statusCode , resBodyStr , err := postBytes (server .URL + `/api/v1/spans` , []byte (spanJSON ), createHeader ("application/json" ))
136
135
assert .NoError (t , err )
137
136
assert .EqualValues (t , http .StatusAccepted , statusCode )
138
137
assert .EqualValues (t , "" , resBodyStr )
139
138
139
+ endpErrJSON := createEndpoint ("" , "127.0.0.A" , "" , 80 )
140
+
140
141
// error zipkinSpanHandler
141
142
handler .zipkinSpansHandler .(* mockZipkinHandler ).err = fmt .Errorf ("Bad times ahead" )
142
- statusCode , resBodyStr , err = postBytes (server .URL + `/api/v1/spans` , []byte (spanJSON ), createHeader ("application/json" ))
143
- assert .NoError (t , err )
144
- assert .EqualValues (t , http .StatusInternalServerError , statusCode )
145
- assert .EqualValues (t , "Cannot submit Zipkin batch: Bad times ahead\n " , resBodyStr )
146
-
147
- // error json no id
148
- spanJSON = createSpan ("bar" , "" , "1234567891234567" , "1234567891234568" , 156 , 15145 , false ,
149
- annoJSON , binAnnoJSON )
150
- statusCode , resBodyStr , err = postBytes (server .URL + `/api/v1/spans` , []byte (spanJSON ), createHeader ("application/json" ))
151
- require .NoError (t , err )
152
- assert .EqualValues (t , http .StatusBadRequest , statusCode )
153
- assert .EqualValues (t , "Unable to process request body: id is not an unsigned long\n " , resBodyStr )
143
+ tests := []struct {
144
+ payload string
145
+ expected string
146
+ statusCode int
147
+ }{
148
+ {spanJSON , "Cannot submit Zipkin batch: Bad times ahead\n " , http .StatusInternalServerError },
149
+ {createSpan ("bar" , "" , "1" , "1" , 156 , 15145 , false , annoJSON , binAnnoJSON ),
150
+ "Unable to process request body: id is not an unsigned long\n " , http .StatusBadRequest },
151
+ {createSpan ("bar" , "ZTA" , "1" , "1" , 156 , 15145 , false , "" , "" ),
152
+ "Unable to process request body: id is not an unsigned long\n " , http .StatusBadRequest },
153
+ {createSpan ("bar" , "1" , "" , "1" , 156 , 15145 , false , "" , createAnno ("cs" , 1 , endpErrJSON )),
154
+ "Unable to process request body: wrong ipv4\n " , http .StatusBadRequest },
155
+ }
154
156
155
- // error toThrift no id no integer
156
- spanJSON = createSpan ("bar" , "Z23456789123456A" , "1234567891234567" , "1234567891234568" , 156 , 15145 , false ,
157
- annoJSON , binAnnoJSON )
158
- statusCode , resBodyStr , err = postBytes (server .URL + `/api/v1/spans` , []byte (spanJSON ), createHeader ("application/json" ))
159
- require .NoError (t , err )
160
- assert .EqualValues (t , http .StatusBadRequest , statusCode )
161
- assert .EqualValues (t , "Unable to process request body: id is not an unsigned long\n " , resBodyStr )
157
+ for _ , test := range tests {
158
+ statusCode , resBodyStr , err = postBytes (server .URL + `/api/v1/spans` , []byte (test .payload ), createHeader ("application/json" ))
159
+ require .NoError (t , err )
160
+ assert .EqualValues (t , test .statusCode , statusCode )
161
+ assert .EqualValues (t , test .expected , resBodyStr )
162
+ }
162
163
}
163
164
164
165
func TestGzipEncoding (t * testing.T ) {
0 commit comments