From 4889c779b7723d3e97b3c17af50042131112b43c Mon Sep 17 00:00:00 2001 From: Alex Ellis Date: Sun, 29 Oct 2017 09:09:20 +0000 Subject: [PATCH] Verify prometheus results are mixed into function list Signed-off-by: Alex Ellis --- gateway/tests/add_metrics_test.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/gateway/tests/add_metrics_test.go b/gateway/tests/add_metrics_test.go index a405005d..5899f82f 100644 --- a/gateway/tests/add_metrics_test.go +++ b/gateway/tests/add_metrics_test.go @@ -15,8 +15,10 @@ type FakePrometheusQueryFetcher struct { } func (q FakePrometheusQueryFetcher) Fetch(query string) (*metrics.VectorQueryResponse, error) { - - return &metrics.VectorQueryResponse{}, nil + val := []byte(`{"status":"success","data":{"resultType":"vector","result":[{"metric":{"code":"200","function_name":"func_echoit"},"value":[1509267827.752,"1"]}]}}`) + queryRes := metrics.VectorQueryResponse{} + err := json.Unmarshal(val, &queryRes) + return &queryRes, err } func makeFakePrometheusQueryFetcher() FakePrometheusQueryFetcher { @@ -40,10 +42,18 @@ func Test_PrometheusMetrics_MixedInto_Services(t *testing.T) { if rr.Header().Get("Content-Type") != "application/json" { t.Errorf("Want application/json content-type, got: %s", rr.Header().Get("Content-Type")) } - if len(rr.Body.String()) == 0 { + body := rr.Body.String() + if len(body) == 0 { t.Errorf("Want content-length > 0, got: %d", len(rr.Body.String())) } - + results := []requests.Function{} + json.Unmarshal([]byte(rr.Body.String()), &results) + if len(results) == 0 { + t.Errorf("Want %d function, got: %d", 1, len(results)) + } + if results[0].InvocationCount != 1 { + t.Errorf("InvocationCount want: %d , got: %f", 1, results[0].InvocationCount) + } } func Test_FunctionsHandler_ReturnsJSONAndOneFunction(t *testing.T) { @@ -75,7 +85,7 @@ func makeFunctionsHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { functions := []requests.Function{ requests.Function{ - Name: "echo", + Name: "func_echoit", Replicas: 0, }, }