Skip to content

Commit 2b406ae

Browse files
committed
fixtures in span_handler tests
1 parent 64499c2 commit 2b406ae

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

cmd/collector/app/zipkin/http_handler_test.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -131,34 +131,35 @@ func TestJsonFormat(t *testing.T) {
131131
binAnnoJSON := createBinAnno("http.status_code", "200", endpJSON)
132132
spanJSON := createSpan("bar", "1234567891234565", "1234567891234567", "1234567891234568", 156, 15145, false,
133133
annoJSON, binAnnoJSON)
134-
135134
statusCode, resBodyStr, err := postBytes(server.URL+`/api/v1/spans`, []byte(spanJSON), createHeader("application/json"))
136135
assert.NoError(t, err)
137136
assert.EqualValues(t, http.StatusAccepted, statusCode)
138137
assert.EqualValues(t, "", resBodyStr)
139138

139+
endpErrJSON := createEndpoint("", "127.0.0.A", "", 80)
140+
140141
// error zipkinSpanHandler
141142
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+
}
154156

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+
}
162163
}
163164

164165
func TestGzipEncoding(t *testing.T) {

0 commit comments

Comments
 (0)