(t *testing.T)
| 920 | } |
| 921 | |
| 922 | func TestWipeMetricStore(t *testing.T) { |
| 923 | // Create MockMetricStore with a few GroupingKeyToMetricGroup metrics |
| 924 | // so they can be returned by GetMetricFamiliesMap() to later send write |
| 925 | // requests for each of them. |
| 926 | metricCount := 5 |
| 927 | mgs := storage.GroupingKeyToMetricGroup{} |
| 928 | for i := range metricCount { |
| 929 | mgs[fmt.Sprint(i)] = storage.MetricGroup{} |
| 930 | } |
| 931 | mms := MockMetricStore{metricGroups: mgs} |
| 932 | |
| 933 | // Wipe handler should return 202 and delete all metrics. |
| 934 | wipeHandler := WipeMetricStore(&mms, logger) |
| 935 | w := httptest.NewRecorder() |
| 936 | // Then handler is routed to the handler based on verb and path in main.go |
| 937 | // therefore (and for now) we use the request to only record the returned status code. |
| 938 | req, err := http.NewRequest("PUT", "http://example.org", &bytes.Buffer{}) |
| 939 | if err != nil { |
| 940 | t.Fatal(err) |
| 941 | } |
| 942 | wipeHandler.ServeHTTP(w, req) |
| 943 | |
| 944 | if w.Code != http.StatusAccepted { |
| 945 | t.Errorf("status code should be %d", http.StatusAccepted) |
| 946 | } |
| 947 | |
| 948 | if len(mms.writeRequests) != metricCount { |
| 949 | t.Errorf("there should be %d write requests, got %d instead", metricCount, len(mms.writeRequests)) |
| 950 | } |
| 951 | |
| 952 | // Were all the writeRequest deletes?. |
| 953 | for i, wr := range mms.writeRequests { |
| 954 | if wr.MetricFamilies != nil { |
| 955 | t.Errorf("writeRequest at index %d was not a delete request", i) |
| 956 | } |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | // verifyMetricFamily compares a MetricFamily against an expected text-format |
| 961 | // representation. It unmarshals expText into a proto message first, then |
nothing calls this directly
no test coverage detected
searching dependent graphs…