package cli import ( "net/http" "net/http/httptest" "testing" ) func TestAQueuedChangeIsNotReportedAsAnError(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusAccepted) _, _ = w.Write([]byte(`{"queued":["r1"]}`)) })) defer srv.Close() var out struct { Queued []string `json:"queued"` } if err := newCtlClient(srv.URL).post(t.Context(), "/api/v1/restart", []byte(`{}`), &out); err != nil { t.Fatalf("202 read as a failure: %v", err) } if len(out.Queued) != 1 { t.Errorf("the body of a 202 was not read: %+v", out) } }