...
1
16
17 package spec3_test
18
19 import (
20 "encoding/json"
21 "testing"
22
23 "github.com/google/go-cmp/cmp"
24 "github.com/stretchr/testify/require"
25 "k8s.io/kube-openapi/pkg/spec3"
26 jsontesting "k8s.io/kube-openapi/pkg/util/jsontesting"
27 "k8s.io/kube-openapi/pkg/validation/spec"
28 )
29
30 func TestExternalDocumentationRoundTrip(t *testing.T) {
31 cases := []jsontesting.RoundTripTestCase{
32 {
33 Name: "Basic Roundtrip",
34 Object: &spec3.ExternalDocumentation{
35 spec3.ExternalDocumentationProps{
36 Description: "foo",
37 },
38 spec.VendorExtensible{Extensions: spec.Extensions{
39 "x-framework": "go-swagger",
40 }},
41 },
42 },
43 }
44
45 for _, tcase := range cases {
46 t.Run(tcase.Name, func(t *testing.T) {
47 require.NoError(t, tcase.RoundTripTest(&spec3.ExternalDocumentation{}))
48 })
49 }
50 }
51
52 func TestExternalDocumentationJSONSerialization(t *testing.T) {
53 cases := []struct {
54 name string
55 target *spec3.ExternalDocumentation
56 expectedOutput string
57 }{
58
59 {
60 name: "basic",
61 target: &spec3.ExternalDocumentation{
62 ExternalDocumentationProps: spec3.ExternalDocumentationProps{
63 Description: "Find more info here",
64 URL: "https://example.com",
65 },
66 },
67 expectedOutput: `{"description":"Find more info here","url":"https://example.com"}`,
68 },
69 }
70 for _, tc := range cases {
71 t.Run(tc.name, func(t *testing.T) {
72 rawTarget, err := json.Marshal(tc.target)
73 if err != nil {
74 t.Fatal(err)
75 }
76 serializedTarget := string(rawTarget)
77 if !cmp.Equal(serializedTarget, tc.expectedOutput) {
78 t.Fatalf("diff %s", cmp.Diff(serializedTarget, tc.expectedOutput))
79 }
80 })
81 }
82 }
83
View as plain text