Skip to content

Commit ee81611

Browse files
committed
Adjust openapi test to avoid mutation on write
1 parent d879965 commit ee81611

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

staging/src/k8s.io/client-go/discovery/discovery_client_test.go

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -402,42 +402,44 @@ func TestGetServerResources(t *testing.T) {
402402
}
403403
}
404404

405-
var returnedOpenAPI = openapi_v2.Document{
406-
Definitions: &openapi_v2.Definitions{
407-
AdditionalProperties: []*openapi_v2.NamedSchema{
408-
{
409-
Name: "fake.type.1",
410-
Value: &openapi_v2.Schema{
411-
Properties: &openapi_v2.Properties{
412-
AdditionalProperties: []*openapi_v2.NamedSchema{
413-
{
414-
Name: "count",
415-
Value: &openapi_v2.Schema{
416-
Type: &openapi_v2.TypeItem{
417-
Value: []string{"integer"},
405+
func returnedOpenAPI() *openapi_v2.Document {
406+
return &openapi_v2.Document{
407+
Definitions: &openapi_v2.Definitions{
408+
AdditionalProperties: []*openapi_v2.NamedSchema{
409+
{
410+
Name: "fake.type.1",
411+
Value: &openapi_v2.Schema{
412+
Properties: &openapi_v2.Properties{
413+
AdditionalProperties: []*openapi_v2.NamedSchema{
414+
{
415+
Name: "count",
416+
Value: &openapi_v2.Schema{
417+
Type: &openapi_v2.TypeItem{
418+
Value: []string{"integer"},
419+
},
418420
},
419421
},
420422
},
421423
},
422424
},
423425
},
424-
},
425-
{
426-
Name: "fake.type.2",
427-
Value: &openapi_v2.Schema{
428-
Properties: &openapi_v2.Properties{
429-
AdditionalProperties: []*openapi_v2.NamedSchema{
430-
{
431-
Name: "count",
432-
Value: &openapi_v2.Schema{
433-
Type: &openapi_v2.TypeItem{
434-
Value: []string{"array"},
435-
},
436-
Items: &openapi_v2.ItemsItem{
437-
Schema: []*openapi_v2.Schema{
438-
{
439-
Type: &openapi_v2.TypeItem{
440-
Value: []string{"string"},
426+
{
427+
Name: "fake.type.2",
428+
Value: &openapi_v2.Schema{
429+
Properties: &openapi_v2.Properties{
430+
AdditionalProperties: []*openapi_v2.NamedSchema{
431+
{
432+
Name: "count",
433+
Value: &openapi_v2.Schema{
434+
Type: &openapi_v2.TypeItem{
435+
Value: []string{"array"},
436+
},
437+
Items: &openapi_v2.ItemsItem{
438+
Schema: []*openapi_v2.Schema{
439+
{
440+
Type: &openapi_v2.TypeItem{
441+
Value: []string{"string"},
442+
},
441443
},
442444
},
443445
},
@@ -449,7 +451,7 @@ var returnedOpenAPI = openapi_v2.Document{
449451
},
450452
},
451453
},
452-
},
454+
}
453455
}
454456

455457
func openapiSchemaDeprecatedFakeServer(status int) (*httptest.Server, error) {
@@ -469,7 +471,7 @@ func openapiSchemaDeprecatedFakeServer(status int) (*httptest.Server, error) {
469471

470472
mime.AddExtensionType(".pb-v1", "application/com.github.googleapis.gnostic.OpenAPIv2@68f4ded+protobuf")
471473

472-
output, err := proto.Marshal(&returnedOpenAPI)
474+
output, err := proto.Marshal(returnedOpenAPI())
473475
if err != nil {
474476
sErr = err
475477
return
@@ -496,7 +498,7 @@ func openapiSchemaFakeServer() (*httptest.Server, error) {
496498

497499
mime.AddExtensionType(".pb-v1", "application/com.github.googleapis.gnostic.OpenAPIv2@68f4ded+protobuf")
498500

499-
output, err := proto.Marshal(&returnedOpenAPI)
501+
output, err := proto.Marshal(returnedOpenAPI())
500502
if err != nil {
501503
sErr = err
502504
return
@@ -519,7 +521,7 @@ func TestGetOpenAPISchema(t *testing.T) {
519521
if err != nil {
520522
t.Fatalf("unexpected error getting openapi: %v", err)
521523
}
522-
if e, a := returnedOpenAPI, *got; !reflect.DeepEqual(e, a) {
524+
if e, a := returnedOpenAPI(), got; !reflect.DeepEqual(e, a) {
523525
t.Errorf("expected %v, got %v", e, a)
524526
}
525527
}
@@ -536,7 +538,7 @@ func TestGetOpenAPISchemaForbiddenFallback(t *testing.T) {
536538
if err != nil {
537539
t.Fatalf("unexpected error getting openapi: %v", err)
538540
}
539-
if e, a := returnedOpenAPI, *got; !reflect.DeepEqual(e, a) {
541+
if e, a := returnedOpenAPI(), got; !reflect.DeepEqual(e, a) {
540542
t.Errorf("expected %v, got %v", e, a)
541543
}
542544
}
@@ -553,7 +555,7 @@ func TestGetOpenAPISchemaNotFoundFallback(t *testing.T) {
553555
if err != nil {
554556
t.Fatalf("unexpected error getting openapi: %v", err)
555557
}
556-
if e, a := returnedOpenAPI, *got; !reflect.DeepEqual(e, a) {
558+
if e, a := returnedOpenAPI(), got; !reflect.DeepEqual(e, a) {
557559
t.Errorf("expected %v, got %v", e, a)
558560
}
559561
}
@@ -570,7 +572,7 @@ func TestGetOpenAPISchemaNotAcceptableFallback(t *testing.T) {
570572
if err != nil {
571573
t.Fatalf("unexpected error getting openapi: %v", err)
572574
}
573-
if e, a := returnedOpenAPI, *got; !reflect.DeepEqual(e, a) {
575+
if e, a := returnedOpenAPI(), got; !reflect.DeepEqual(e, a) {
574576
t.Errorf("expected %v, got %v", e, a)
575577
}
576578
}

0 commit comments

Comments
 (0)