initial commit
This commit is contained in:
commit
88c14b627e
224 files changed
+17204
No files matched your search
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user