Adjust openapi test to avoid mutation on write

Kubernetes-commit: ee816114b7ae044f23b4776fdf0c3f04e2ce13e3
This commit is contained in:
Jordan Liggitt 2020-03-31 19:14:19 -04:00 committed by Kubernetes Publisher
parent d847b4c964
commit cd3db5b5a1

View File

@ -402,42 +402,44 @@ func TestGetServerResources(t *testing.T) {
} }
} }
var returnedOpenAPI = openapi_v2.Document{ func returnedOpenAPI() *openapi_v2.Document {
Definitions: &openapi_v2.Definitions{ return &openapi_v2.Document{
AdditionalProperties: []*openapi_v2.NamedSchema{ Definitions: &openapi_v2.Definitions{
{ AdditionalProperties: []*openapi_v2.NamedSchema{
Name: "fake.type.1", {
Value: &openapi_v2.Schema{ Name: "fake.type.1",
Properties: &openapi_v2.Properties{ Value: &openapi_v2.Schema{
AdditionalProperties: []*openapi_v2.NamedSchema{ Properties: &openapi_v2.Properties{
{ AdditionalProperties: []*openapi_v2.NamedSchema{
Name: "count", {
Value: &openapi_v2.Schema{ Name: "count",
Type: &openapi_v2.TypeItem{ Value: &openapi_v2.Schema{
Value: []string{"integer"}, Type: &openapi_v2.TypeItem{
Value: []string{"integer"},
},
}, },
}, },
}, },
}, },
}, },
}, },
}, {
{ Name: "fake.type.2",
Name: "fake.type.2", Value: &openapi_v2.Schema{
Value: &openapi_v2.Schema{ Properties: &openapi_v2.Properties{
Properties: &openapi_v2.Properties{ AdditionalProperties: []*openapi_v2.NamedSchema{
AdditionalProperties: []*openapi_v2.NamedSchema{ {
{ Name: "count",
Name: "count", Value: &openapi_v2.Schema{
Value: &openapi_v2.Schema{ Type: &openapi_v2.TypeItem{
Type: &openapi_v2.TypeItem{ Value: []string{"array"},
Value: []string{"array"}, },
}, Items: &openapi_v2.ItemsItem{
Items: &openapi_v2.ItemsItem{ Schema: []*openapi_v2.Schema{
Schema: []*openapi_v2.Schema{ {
{ Type: &openapi_v2.TypeItem{
Type: &openapi_v2.TypeItem{ Value: []string{"string"},
Value: []string{"string"}, },
}, },
}, },
}, },
@ -449,7 +451,7 @@ var returnedOpenAPI = openapi_v2.Document{
}, },
}, },
}, },
}, }
} }
func openapiSchemaDeprecatedFakeServer(status int) (*httptest.Server, error) { func openapiSchemaDeprecatedFakeServer(status int) (*httptest.Server, error) {
@ -469,7 +471,7 @@ func openapiSchemaDeprecatedFakeServer(status int) (*httptest.Server, error) {
mime.AddExtensionType(".pb-v1", "application/com.github.googleapis.gnostic.OpenAPIv2@68f4ded+protobuf") mime.AddExtensionType(".pb-v1", "application/com.github.googleapis.gnostic.OpenAPIv2@68f4ded+protobuf")
output, err := proto.Marshal(&returnedOpenAPI) output, err := proto.Marshal(returnedOpenAPI())
if err != nil { if err != nil {
sErr = err sErr = err
return return
@ -496,7 +498,7 @@ func openapiSchemaFakeServer() (*httptest.Server, error) {
mime.AddExtensionType(".pb-v1", "application/com.github.googleapis.gnostic.OpenAPIv2@68f4ded+protobuf") mime.AddExtensionType(".pb-v1", "application/com.github.googleapis.gnostic.OpenAPIv2@68f4ded+protobuf")
output, err := proto.Marshal(&returnedOpenAPI) output, err := proto.Marshal(returnedOpenAPI())
if err != nil { if err != nil {
sErr = err sErr = err
return return
@ -519,7 +521,7 @@ func TestGetOpenAPISchema(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unexpected error getting openapi: %v", err) t.Fatalf("unexpected error getting openapi: %v", err)
} }
if e, a := returnedOpenAPI, *got; !reflect.DeepEqual(e, a) { if e, a := returnedOpenAPI(), got; !reflect.DeepEqual(e, a) {
t.Errorf("expected %v, got %v", e, a) t.Errorf("expected %v, got %v", e, a)
} }
} }
@ -536,7 +538,7 @@ func TestGetOpenAPISchemaForbiddenFallback(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unexpected error getting openapi: %v", err) t.Fatalf("unexpected error getting openapi: %v", err)
} }
if e, a := returnedOpenAPI, *got; !reflect.DeepEqual(e, a) { if e, a := returnedOpenAPI(), got; !reflect.DeepEqual(e, a) {
t.Errorf("expected %v, got %v", e, a) t.Errorf("expected %v, got %v", e, a)
} }
} }
@ -553,7 +555,7 @@ func TestGetOpenAPISchemaNotFoundFallback(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unexpected error getting openapi: %v", err) t.Fatalf("unexpected error getting openapi: %v", err)
} }
if e, a := returnedOpenAPI, *got; !reflect.DeepEqual(e, a) { if e, a := returnedOpenAPI(), got; !reflect.DeepEqual(e, a) {
t.Errorf("expected %v, got %v", e, a) t.Errorf("expected %v, got %v", e, a)
} }
} }
@ -570,7 +572,7 @@ func TestGetOpenAPISchemaNotAcceptableFallback(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("unexpected error getting openapi: %v", err) t.Fatalf("unexpected error getting openapi: %v", err)
} }
if e, a := returnedOpenAPI, *got; !reflect.DeepEqual(e, a) { if e, a := returnedOpenAPI(), got; !reflect.DeepEqual(e, a) {
t.Errorf("expected %v, got %v", e, a) t.Errorf("expected %v, got %v", e, a)
} }
} }