package compat import ( "context" "encoding/json" "net/http" "net/http/httptest" "testing" ) type compatibilityHandler struct{} func (compatibilityHandler) GetProbe(context.Context, GetProbeParams) (*NullablePayload, error) { return &NullablePayload{}, nil } func (compatibilityHandler) PurgeProbe(context.Context) error { return nil } func TestGeneratedServerRejectsInvalidInput(t *testing.T) { server, err := NewServer(compatibilityHandler{}) if err != nil { t.Fatalf("NewServer() error = %v", err) } response := httptest.NewRecorder() server.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/probe?state=invalid", nil)) if response.Code != http.StatusBadRequest { t.Fatalf("status code = %d, want %d", response.Code, http.StatusBadRequest) } } func TestNullableTypeArrayPreservesNull(t *testing.T) { var payload NullablePayload if err := json.Unmarshal([]byte(`{"value":null}`), &payload); err != nil { t.Fatalf("decode nullable payload: %v", err) } if !payload.Value.IsNull() { t.Fatal("nullable value was not represented as null") } } func TestAdditionalOperationIsRouted(t *testing.T) { server, err := NewServer(compatibilityHandler{}) if err != nil { t.Fatalf("NewServer() error = %v", err) } response := httptest.NewRecorder() server.ServeHTTP(response, httptest.NewRequest("PURGE", "/probe", nil)) if response.Code != http.StatusNoContent { t.Fatalf("status code = %d, want %d", response.Code, http.StatusNoContent) } }