forked from longtao.wu/droboticflow
32 lines
1.2 KiB
Go
32 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"droboticflow/internal/store"
|
|
)
|
|
|
|
func TestWorkforcePublicationPendingIsNotAnEmptyReport(t *testing.T) {
|
|
r := httptest.NewRequest(http.MethodGet, "/report", nil)
|
|
r.Header.Set("Accept", "application/vnd.droboticflow.prepared+json")
|
|
w := httptest.NewRecorder()
|
|
if !renderWorkforcePublicationPending(w, r, fmt.Errorf("report: %w", store.ErrWorkforcePublicationPending)) || w.Code != http.StatusAccepted || w.Header().Get("Retry-After") != "1" {
|
|
t.Fatalf("publication readiness response: %d %s", w.Code, w.Body.String())
|
|
}
|
|
legacy := httptest.NewRecorder()
|
|
if !renderWorkforcePublicationPending(legacy, httptest.NewRequest(http.MethodGet, "/report", nil), store.ErrWorkforcePublicationPending) || legacy.Code != http.StatusServiceUnavailable {
|
|
t.Fatal("legacy client received a successful non-report body")
|
|
}
|
|
|
|
for _, err := range []error{nil, store.ErrQueryReplicaNotReady, errors.New("permission denied")} {
|
|
w = httptest.NewRecorder()
|
|
if renderWorkforcePublicationPending(w, r, err) || w.Body.Len() != 0 {
|
|
t.Fatal("unrelated errors must retain their existing handling")
|
|
}
|
|
}
|
|
}
|