Skip to content

Commit

Permalink
fixtures in span_handler tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pavolloffay committed Aug 16, 2017
1 parent 64499c2 commit 2b406ae
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions cmd/collector/app/zipkin/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,34 +131,35 @@ func TestJsonFormat(t *testing.T) {
binAnnoJSON := createBinAnno("http.status_code", "200", endpJSON)
spanJSON := createSpan("bar", "1234567891234565", "1234567891234567", "1234567891234568", 156, 15145, false,
annoJSON, binAnnoJSON)

statusCode, resBodyStr, err := postBytes(server.URL+`/api/v1/spans`, []byte(spanJSON), createHeader("application/json"))
assert.NoError(t, err)
assert.EqualValues(t, http.StatusAccepted, statusCode)
assert.EqualValues(t, "", resBodyStr)

endpErrJSON := createEndpoint("", "127.0.0.A", "", 80)

// error zipkinSpanHandler
handler.zipkinSpansHandler.(*mockZipkinHandler).err = fmt.Errorf("Bad times ahead")
statusCode, resBodyStr, err = postBytes(server.URL+`/api/v1/spans`, []byte(spanJSON), createHeader("application/json"))
assert.NoError(t, err)
assert.EqualValues(t, http.StatusInternalServerError, statusCode)
assert.EqualValues(t, "Cannot submit Zipkin batch: Bad times ahead\n", resBodyStr)

// error json no id
spanJSON = createSpan("bar", "", "1234567891234567", "1234567891234568", 156, 15145, false,
annoJSON, binAnnoJSON)
statusCode, resBodyStr, err = postBytes(server.URL+`/api/v1/spans`, []byte(spanJSON), createHeader("application/json"))
require.NoError(t, err)
assert.EqualValues(t, http.StatusBadRequest, statusCode)
assert.EqualValues(t, "Unable to process request body: id is not an unsigned long\n", resBodyStr)
tests := []struct {
payload string
expected string
statusCode int
}{
{spanJSON, "Cannot submit Zipkin batch: Bad times ahead\n", http.StatusInternalServerError},
{createSpan("bar", "", "1", "1", 156, 15145, false, annoJSON, binAnnoJSON),
"Unable to process request body: id is not an unsigned long\n", http.StatusBadRequest},
{createSpan("bar", "ZTA", "1", "1", 156, 15145, false, "", ""),
"Unable to process request body: id is not an unsigned long\n", http.StatusBadRequest},
{createSpan("bar", "1", "", "1", 156, 15145, false, "", createAnno("cs", 1, endpErrJSON)),
"Unable to process request body: wrong ipv4\n", http.StatusBadRequest},
}

// error toThrift no id no integer
spanJSON = createSpan("bar", "Z23456789123456A", "1234567891234567", "1234567891234568", 156, 15145, false,
annoJSON, binAnnoJSON)
statusCode, resBodyStr, err = postBytes(server.URL+`/api/v1/spans`, []byte(spanJSON), createHeader("application/json"))
require.NoError(t, err)
assert.EqualValues(t, http.StatusBadRequest, statusCode)
assert.EqualValues(t, "Unable to process request body: id is not an unsigned long\n", resBodyStr)
for _, test := range tests {
statusCode, resBodyStr, err = postBytes(server.URL+`/api/v1/spans`, []byte(test.payload), createHeader("application/json"))
require.NoError(t, err)
assert.EqualValues(t, test.statusCode, statusCode)
assert.EqualValues(t, test.expected, resBodyStr)
}
}

func TestGzipEncoding(t *testing.T) {
Expand Down

0 comments on commit 2b406ae

Please sign in to comment.