MCPcopy
hub / github.com/OpenNHP/opennhp / TestClusters_SortedAndStable

Function TestClusters_SortedAndStable

endpoints/relay/routing_test.go:215–237  ·  view source on GitHub ↗

TestClusters_SortedAndStable verifies the /clusters output is sorted by id, so callers that diff or hash the response don't see Go-map-order churn between requests.

(t *testing.T)

Source from the content-addressed store, hash-verified

213// id, so callers that diff or hash the response don't see Go-map-order
214// churn between requests.
215func TestClusters_SortedAndStable(t *testing.T) {
216 rs := newRoutingTestServer("zeta", "alpha", "mu")
217
218 w := httptest.NewRecorder()
219 rs.handleClusters(w, httptest.NewRequest(http.MethodGet, "/clusters", nil))
220
221 if w.Code != http.StatusOK {
222 t.Fatalf("expected 200, got %d", w.Code)
223 }
224 var got []clusterInfo
225 if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
226 t.Fatalf("response is not JSON: %v", err)
227 }
228 if len(got) != 3 {
229 t.Fatalf("expected 3 clusters, got %d", len(got))
230 }
231 wantOrder := []string{"alpha", "mu", "zeta"}
232 for i := range got {
233 if got[i].ID != wantOrder[i] {
234 t.Errorf("position %d: got id=%q, want %q", i, got[i].ID, wantOrder[i])
235 }
236 }
237}
238
239// TestClusters_NonGetReturns405 keeps the method check on the discovery
240// endpoint in the regression net.

Callers

nothing calls this directly

Calls 3

newRoutingTestServerFunction · 0.85
handleClustersMethod · 0.80
BytesMethod · 0.65

Tested by

no test coverage detected