Add basic test

This commit is contained in:
Alan Bernstein 2020-10-09 16:35:18 -05:00
parent 510902625e
commit ab502a0f8d
2 changed files with 27 additions and 1 deletions

2
api.go
View file

@ -1600,7 +1600,7 @@ func importExistenceColumns(qcx *Qcx, index *Index, columnIDs []uint64) error {
// ShardDistribution returns an object representing the distribution of shards
// across nodes for each index, distinguishing between primary and replica.
// The structure of this information is [indexName][nodeID][primaryOrReplica]uint64.
// This function supports a view in the UI, and
// This function supports a view in the UI.
func (api *API) ShardDistribution(ctx context.Context) map[string]interface{} {
distByIndex := make(map[string]interface{})
maxShards := api.MaxShards(ctx)

View file

@ -400,6 +400,32 @@ func TestHandler_Endpoints(t *testing.T) {
}
})
t.Run("UI/shard-distribution", func(t *testing.T) {
// This tests the response structure, not the shard distribution.
w := httptest.NewRecorder()
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/ui/shard-distribution", nil))
if w.Code != gohttp.StatusOK {
t.Fatalf("unexpected status code: %d", w.Code)
}
ret := mustJSONDecode(t, w.Body)
for indexName := range ret {
indexData := ret[indexName].(map[string]interface{})
for nodeName := range indexData {
nodeData := indexData[nodeName].(map[string]interface{})
_, hasPrimary := nodeData["primary-shards"]
_, hasReplica := nodeData["replica-shards"]
responseOK := hasPrimary && hasReplica
if !responseOK {
t.Fatalf("unexpected response structure")
}
}
}
})
t.Run("Metrics", func(t *testing.T) {
w := httptest.NewRecorder()
h.ServeHTTP(w, test.MustNewHTTPRequest("GET", "/metrics", nil))