| 1 | /* |
| 2 | Copyright 2022 The Kubernetes Authors. |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package spec_testscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/ |
| 18 | |
| 19 | import ( |
| 20 | "encoding/jsonscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/" |
| 21 | "ioscip-go gomod github.com/golang/go/src go1.21 io/" |
| 22 | "osscip-go gomod github.com/golang/go/src go1.21 os/" |
| 23 | "reflectscip-go gomod github.com/golang/go/src go1.21 reflect/" |
| 24 | "testingscip-go gomod github.com/golang/go/src go1.21 testing/" |
| 25 | "timescip-go gomod github.com/golang/go/src go1.21 time/" |
| 26 | |
| 27 | "github.com/google/gnostic-models/compilerscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/compiler`/" |
| 28 | openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/ "github.com/google/gnostic-models/openapiv2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/" |
| 29 | "github.com/google/go-cmp/cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/" |
| 30 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/ "github.com/google/gofuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/" |
| 31 | "github.com/stretchr/testify/requirescip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/" |
| 32 | "google.golang.org/protobuf/protoscip-go gomod google.golang.org/protobuf v1.35.1 `google.golang.org/protobuf/proto`/" |
| 33 | "gopkg.in/yaml.v3scip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/" |
| 34 | jsontestingscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/util/jsontesting`/ "k8s.io/kube-openapi/pkg/util/jsontestingscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/util/jsontesting`/" |
| 35 | . "k8s.io/kube-openapi/pkg/validation/specscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/" |
| 36 | ) |
| 37 | |
| 38 | func gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().(t testingscip-go gomod github.com/golang/go/src go1.21 testing/.TBscip-go gomod github.com/golang/go/src go1.21 testing/TB#, fuzzer *fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/.Fuzzerscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#) { |
| 39 | fuzzer.Funcsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#Funcs().( |
| 40 | SwaggerFuzzFuncsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/SwaggerFuzzFuncs...., |
| 41 | ) |
| 42 | |
| 43 | expected := Swaggerscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#{} |
| 44 | fuzzer.Fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#Fuzz().(&expected) |
| 45 | |
| 46 | // Convert to gnostic via JSON to compare |
| 47 | jsonBytes, err := expected.MarshalJSONscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#MarshalJSON().() |
| 48 | requirescip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 49 | |
| 50 | t.Logscip-go gomod github.com/golang/go/src go1.21 testing/TB#Log().("Specimen", string(jsonBytes)) |
| 51 | |
| 52 | gnosticSpec, err := openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.ParseDocumentscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/ParseDocument().(jsonBytes) |
| 53 | requirescip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 54 | |
| 55 | actual := Swaggerscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#{} |
| 56 | ok, err := actual.FromGnosticscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#FromGnostic().(gnosticSpec) |
| 57 | requirescip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 58 | requirescip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/.Truescip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/True().(t, ok) |
| 59 | if !cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/.Equalscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/Equal().(expected, actual, SwaggerDiffOptionsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/SwaggerDiffOptions....) { |
| 60 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/TB#Fatal().(cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/Diff().(expected, actual, SwaggerDiffOptionsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/SwaggerDiffOptions....)) |
| 61 | } |
| 62 | |
| 63 | newJsonBytes, err := actual.MarshalJSONscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#MarshalJSON().() |
| 64 | requirescip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/.NoErrorscip-go gomod github.com/stretchr/testify v1.9.0 `github.com/stretchr/testify/require`/NoError().(t, err) |
| 65 | if err := jsontestingscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/util/jsontesting`/.JsonComparescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/util/jsontesting`/JsonCompare().(jsonBytes, newJsonBytes); err != nil { |
| 66 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/TB#Fatal().(err) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | func TestGnosticConversionSmallDeterministicscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionSmallDeterministic().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 71 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 72 | t, |
| 73 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 74 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(15). |
| 75 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.8). |
| 76 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(10). |
| 77 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(1, 2), |
| 78 | ) |
| 79 | } |
| 80 | |
| 81 | func TestGnosticConversionSmallDeterministic2scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionSmallDeterministic2().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 82 | // A failed case of TestGnosticConversionSmallRandom |
| 83 | // which failed during development/testing loop |
| 84 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 85 | t, |
| 86 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 87 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(1646770841). |
| 88 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.8). |
| 89 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(10). |
| 90 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(1, 2), |
| 91 | ) |
| 92 | } |
| 93 | |
| 94 | func TestGnosticConversionSmallDeterministic3scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionSmallDeterministic3().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 95 | // A failed case of TestGnosticConversionSmallRandom |
| 96 | // which failed during development/testing loop |
| 97 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 98 | t, |
| 99 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 100 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(1646772024). |
| 101 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.8). |
| 102 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(10). |
| 103 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(1, 2), |
| 104 | ) |
| 105 | } |
| 106 | |
| 107 | func TestGnosticConversionSmallDeterministic4scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionSmallDeterministic4().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 108 | // A failed case of TestGnosticConversionSmallRandom |
| 109 | // which failed during development/testing loop |
| 110 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 111 | t, |
| 112 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 113 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(1646791953). |
| 114 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.8). |
| 115 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(10). |
| 116 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(1, 2), |
| 117 | ) |
| 118 | } |
| 119 | |
| 120 | func TestGnosticConversionSmallDeterministic5scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionSmallDeterministic5().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 121 | // A failed case of TestGnosticConversionSmallRandom |
| 122 | // which failed during development/testing loop |
| 123 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 124 | t, |
| 125 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 126 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(1646940131). |
| 127 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.8). |
| 128 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(10). |
| 129 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(1, 2), |
| 130 | ) |
| 131 | } |
| 132 | |
| 133 | func TestGnosticConversionSmallDeterministic6scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionSmallDeterministic6().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 134 | // A failed case of TestGnosticConversionSmallRandom |
| 135 | // which failed during development/testing loop |
| 136 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 137 | t, |
| 138 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 139 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(1646941926). |
| 140 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.8). |
| 141 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(10). |
| 142 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(1, 2), |
| 143 | ) |
| 144 | } |
| 145 | |
| 146 | func TestGnosticConversionSmallDeterministic7scip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionSmallDeterministic7().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 147 | // A failed case of TestGnosticConversionSmallRandom |
| 148 | // which failed during development/testing loop |
| 149 | // This case did not convert nil/empty array within OperationProps.Security |
| 150 | // correctly |
| 151 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 152 | t, |
| 153 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 154 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(1647297721085690000). |
| 155 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.8). |
| 156 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(10). |
| 157 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(1, 2), |
| 158 | ) |
| 159 | } |
| 160 | |
| 161 | func TestGnosticConversionSmallRandomscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionSmallRandom().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 162 | seed := timescip-go gomod github.com/golang/go/src go1.21 time/.Nowscip-go gomod github.com/golang/go/src go1.21 time/Now().().UnixNanoscip-go gomod github.com/golang/go/src go1.21 time/Time#UnixNano().() |
| 163 | t.Logscip-go gomod github.com/golang/go/src go1.21 testing/common#Log().("Using seed: ", seed) |
| 164 | fuzzer := fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 165 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(seed). |
| 166 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.8). |
| 167 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(10). |
| 168 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(1, 2) |
| 169 | |
| 170 | for i := 0; i <= 50; i++ { |
| 171 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 172 | t, |
| 173 | fuzzer, |
| 174 | ) |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | func TestGnosticConversionMediumDeterministicscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionMediumDeterministic().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 179 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 180 | t, |
| 181 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 182 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(15). |
| 183 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.4). |
| 184 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(12). |
| 185 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(3, 5), |
| 186 | ) |
| 187 | } |
| 188 | |
| 189 | func TestGnosticConversionLargeDeterministicscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionLargeDeterministic().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 190 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 191 | t, |
| 192 | fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 193 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(15). |
| 194 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0.1). |
| 195 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(15). |
| 196 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(3, 5), |
| 197 | ) |
| 198 | } |
| 199 | |
| 200 | func TestGnosticConversionLargeRandomscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestGnosticConversionLargeRandom().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 201 | var seed int64 = timescip-go gomod github.com/golang/go/src go1.21 time/.Nowscip-go gomod github.com/golang/go/src go1.21 time/Now().().UnixNanoscip-go gomod github.com/golang/go/src go1.21 time/Time#UnixNano().() |
| 202 | t.Logscip-go gomod github.com/golang/go/src go1.21 testing/common#Log().("Using seed: ", seed) |
| 203 | fuzzer := fuzzscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/. |
| 204 | NewWithSeedscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/NewWithSeed().(seed). |
| 205 | NilChancescip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NilChance().(0). |
| 206 | MaxDepthscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#MaxDepth().(15). |
| 207 | NumElementsscip-go gomod github.com/google/gofuzz v1.2.0 `github.com/google/gofuzz`/Fuzzer#NumElements().(3, 5) |
| 208 | |
| 209 | for i := 0; i < 5; i++ { |
| 210 | gnosticCommonTestscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/gnosticCommonTest().( |
| 211 | t, |
| 212 | fuzzer, |
| 213 | ) |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | func BenchmarkGnosticConversionscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/BenchmarkGnosticConversion().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 218 | // Download kube-openapi swagger json |
| 219 | swagFile, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Openscip-go gomod github.com/golang/go/src go1.21 os/Open().("../../schemaconv/testdata/swagger.json") |
| 220 | if err != nil { |
| 221 | b.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 222 | } |
| 223 | defer swagFile.Closescip-go gomod github.com/golang/go/src go1.21 os/File#Close().() |
| 224 | |
| 225 | originalJSON, err := ioscip-go gomod github.com/golang/go/src go1.21 io/.ReadAllscip-go gomod github.com/golang/go/src go1.21 io/ReadAll().(swagFile) |
| 226 | if err != nil { |
| 227 | b.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 228 | } |
| 229 | |
| 230 | // Parse into kube-openapi types |
| 231 | var result *Swaggerscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger# |
| 232 | b.Runscip-go gomod github.com/golang/go/src go1.21 testing/B#Run().("json->swagger", func(b2 *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 233 | for i := 0; i < b2.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 234 | if err := jsonscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/Unmarshal().(originalJSON, &result); err != nil { |
| 235 | b2.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 236 | } |
| 237 | } |
| 238 | }) |
| 239 | |
| 240 | // Convert to JSON |
| 241 | var encodedJSON []byte |
| 242 | b.Runscip-go gomod github.com/golang/go/src go1.21 testing/B#Run().("swagger->json", func(b2 *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 243 | for i := 0; i < b2.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 244 | encodedJSON, err = jsonscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/Marshal().(result) |
| 245 | if err != nil { |
| 246 | b2.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 247 | } |
| 248 | } |
| 249 | }) |
| 250 | |
| 251 | // Convert to gnostic |
| 252 | var originalGnostic *openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.Documentscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/Document# |
| 253 | b.Runscip-go gomod github.com/golang/go/src go1.21 testing/B#Run().("json->gnostic", func(b2 *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 254 | for i := 0; i < b2.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 255 | originalGnostic, err = openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.ParseDocumentscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/ParseDocument().(encodedJSON) |
| 256 | if err != nil { |
| 257 | b2.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 258 | } |
| 259 | } |
| 260 | }) |
| 261 | |
| 262 | // Convert to PB |
| 263 | var encodedProto []byte |
| 264 | b.Runscip-go gomod github.com/golang/go/src go1.21 testing/B#Run().("gnostic->pb", func(b2 *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 265 | for i := 0; i < b2.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 266 | encodedProto, err = protoscip-go gomod google.golang.org/protobuf v1.35.1 `google.golang.org/protobuf/proto`/.Marshalscip-go gomod google.golang.org/protobuf v1.35.1 `google.golang.org/protobuf/proto`/Marshal().(originalGnostic) |
| 267 | if err != nil { |
| 268 | b2.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 269 | } |
| 270 | } |
| 271 | }) |
| 272 | |
| 273 | // Convert to gnostic |
| 274 | var backToGnostic openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.Documentscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/Document# |
| 275 | b.Runscip-go gomod github.com/golang/go/src go1.21 testing/B#Run().("pb->gnostic", func(b2 *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 276 | for i := 0; i < b2.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 277 | if err := protoscip-go gomod google.golang.org/protobuf v1.35.1 `google.golang.org/protobuf/proto`/.Unmarshalscip-go gomod google.golang.org/protobuf v1.35.1 `google.golang.org/protobuf/proto`/Unmarshal().(encodedProto, &backToGnostic); err != nil { |
| 278 | b2.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 279 | } |
| 280 | } |
| 281 | }) |
| 282 | |
| 283 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 284 | b.Runscip-go gomod github.com/golang/go/src go1.21 testing/B#Run().("gnostic->kube", func(b2 *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 285 | for i := 0; i < b2.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 286 | decodedSwagger := &Swaggerscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#{} |
| 287 | if ok, err := decodedSwagger.FromGnosticscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#FromGnostic().(&backToGnostic); err != nil { |
| 288 | b2.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 289 | } else if !ok { |
| 290 | b2.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().("conversion lost data") |
| 291 | } |
| 292 | } |
| 293 | }) |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // Ensure all variants of SecurityDefinition are being exercised by tests |
| 298 | func TestSecurityDefinitionVariantsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestSecurityDefinitionVariants().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 299 | type TestPattern struct { |
| 300 | Name string |
| 301 | Pattern string |
| 302 | } |
| 303 | |
| 304 | patterns := []TestPattern{ |
| 305 | { |
| 306 | Name: "Basic Authentication", |
| 307 | Pattern: `{"type": "basic", "description": "cool basic auth"}`, |
| 308 | }, |
| 309 | { |
| 310 | Name: "API Key Query", |
| 311 | Pattern: `{"type": "apiKey", "description": "cool api key auth", "in": "query", "name": "coolAuth"}`, |
| 312 | }, |
| 313 | { |
| 314 | Name: "API Key Header", |
| 315 | Pattern: `{"type": "apiKey", "description": "cool api key auth", "in": "header", "name": "coolAuth"}`, |
| 316 | }, |
| 317 | { |
| 318 | Name: "OAuth2 Implicit", |
| 319 | Pattern: `{"type": "oauth2", "flow": "implicit", "authorizationUrl": "https://google.com", "scopes": {"scope1": "a scope", "scope2": "a scope"}, "description": "cool oauth2 auth"}`, |
| 320 | }, |
| 321 | { |
| 322 | Name: "OAuth2 Password", |
| 323 | Pattern: `{"type": "oauth2", "flow": "password", "tokenUrl": "https://google.com", "scopes": {"scope1": "a scope", "scope2": "a scope"}, "description": "cool oauth2 auth"}`, |
| 324 | }, |
| 325 | { |
| 326 | Name: "OAuth2 Application", |
| 327 | Pattern: `{"type": "oauth2", "flow": "application", "tokenUrl": "https://google.com", "scopes": {"scope1": "a scope", "scope2": "a scope"}, "description": "cool oauth2 auth"}`, |
| 328 | }, |
| 329 | { |
| 330 | Name: "OAuth2 Access Code", |
| 331 | Pattern: `{"type": "oauth2", "flow": "accessCode", "authorizationUrl": "https://google.com", "tokenUrl": "https://google.com", "scopes": {"scope1": "a scope", "scope2": "a scope"}, "description": "cool oauth2 auth"}`, |
| 332 | }, |
| 333 | } |
| 334 | |
| 335 | for _, p := range patterns { |
| 336 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(p.Name, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 337 | // Parse JSON into yaml |
| 338 | var nodes yamlscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/.Nodescip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/Node# |
| 339 | if err := yamlscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/.Unmarshalscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/Unmarshal().([]byte(p.Pattern), &nodes); err != nil { |
| 340 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 341 | return |
| 342 | } else if len(nodes.Contentscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/Node#Content.) != 1 { |
| 343 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("unexpected yaml parse result") |
| 344 | return |
| 345 | } |
| 346 | |
| 347 | root := nodes.Contentscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/Node#Content.[0] |
| 348 | |
| 349 | parsed, err := openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.NewSecurityDefinitionsItemscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/NewSecurityDefinitionsItem().(root, compilerscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/compiler`/.NewContextWithExtensionsscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/compiler`/NewContextWithExtensions().("$root", root, nil, nil)) |
| 350 | if err != nil { |
| 351 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 352 | return |
| 353 | } |
| 354 | |
| 355 | converted := SecuritySchemescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/SecurityScheme#{} |
| 356 | if err := converted.FromGnosticscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/SecurityScheme#FromGnostic().(parsed); err != nil { |
| 357 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 358 | return |
| 359 | } |
| 360 | |
| 361 | // Ensure that the same JSON parsed via kube-openapi gives the same |
| 362 | // result |
| 363 | var expected SecuritySchemescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/SecurityScheme# |
| 364 | if err := jsonscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/Unmarshal().([]byte(p.Pattern), &expected); err != nil { |
| 365 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 366 | return |
| 367 | } else if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(expected, converted) { |
| 368 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("expected equal values: %v", cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/Diff().(expected, converted, SwaggerDiffOptionsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/SwaggerDiffOptions....)) |
| 369 | return |
| 370 | } |
| 371 | }) |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // Ensure all variants of Parameter are being exercised by tests |
| 376 | func TestParamVariantsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestParamVariants().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 377 | type TestPattern struct { |
| 378 | Name string |
| 379 | Pattern string |
| 380 | } |
| 381 | |
| 382 | patterns := []TestPattern{ |
| 383 | { |
| 384 | Name: "Body Parameter", |
| 385 | Pattern: `{"in": "body", "name": "myBodyParam", "schema": {}}`, |
| 386 | }, |
| 387 | { |
| 388 | Name: "NonBody Header Parameter", |
| 389 | Pattern: `{"in": "header", "name": "myHeaderParam", "description": "a cool parameter", "type": "string", "collectionFormat": "pipes"}`, |
| 390 | }, |
| 391 | { |
| 392 | Name: "NonBody FormData Parameter", |
| 393 | Pattern: `{"in": "formData", "name": "myFormDataParam", "description": "a cool parameter", "type": "string", "collectionFormat": "pipes"}`, |
| 394 | }, |
| 395 | { |
| 396 | Name: "NonBody Query Parameter", |
| 397 | Pattern: `{"in": "query", "name": "myQueryParam", "description": "a cool parameter", "type": "string", "collectionFormat": "pipes"}`, |
| 398 | }, |
| 399 | { |
| 400 | Name: "NonBody Path Parameter", |
| 401 | Pattern: `{"required": true, "in": "path", "name": "myPathParam", "description": "a cool parameter", "type": "string", "collectionFormat": "pipes"}`, |
| 402 | }, |
| 403 | } |
| 404 | |
| 405 | for _, p := range patterns { |
| 406 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(p.Name, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 407 | // Parse JSON into yaml |
| 408 | var nodes yamlscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/.Nodescip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/Node# |
| 409 | if err := yamlscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/.Unmarshalscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/Unmarshal().([]byte(p.Pattern), &nodes); err != nil { |
| 410 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 411 | return |
| 412 | } else if len(nodes.Contentscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/Node#Content.) != 1 { |
| 413 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("unexpected yaml parse result") |
| 414 | return |
| 415 | } |
| 416 | |
| 417 | root := nodes.Contentscip-go gomod gopkg.in/yaml.v3 v3.0.1 `gopkg.in/yaml.v3`/Node#Content.[0] |
| 418 | |
| 419 | ctx := compilerscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/compiler`/.NewContextWithExtensionsscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/compiler`/NewContextWithExtensions().("$root", root, nil, nil) |
| 420 | parsed, err := openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.NewParameterscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/NewParameter().(root, ctx) |
| 421 | if err != nil { |
| 422 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 423 | return |
| 424 | } |
| 425 | |
| 426 | converted := Parameterscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Parameter#{} |
| 427 | if ok, err := converted.FromGnosticscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Parameter#FromGnostic().(parsed); err != nil { |
| 428 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 429 | return |
| 430 | } else if !ok { |
| 431 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("expected no data loss while converting parameter: %v", p.Pattern) |
| 432 | return |
| 433 | } |
| 434 | |
| 435 | // Ensure that the same JSON parsed via kube-openapi gives the same |
| 436 | // result |
| 437 | var expected Parameterscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Parameter# |
| 438 | if err := jsonscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/Unmarshal().([]byte(p.Pattern), &expected); err != nil { |
| 439 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 440 | return |
| 441 | } else if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(expected, converted) { |
| 442 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("expected equal values: %v", cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/Diff().(expected, converted, SwaggerDiffOptionsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/SwaggerDiffOptions....)) |
| 443 | return |
| 444 | } |
| 445 | }) |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | // Test that a few patterns of obvious data loss are detected |
| 450 | func TestCommonDataLossscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestCommonDataLoss().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 451 | type TestPattern struct { |
| 452 | Name string |
| 453 | BadInstance string |
| 454 | FixedInstance string |
| 455 | } |
| 456 | |
| 457 | patterns := []TestPattern{ |
| 458 | { |
| 459 | Name: "License with Vendor Extension", |
| 460 | BadInstance: `{"swagger": "2.0", "info": {"title": "test", "version": "1.0", "license": {"name": "MIT", "x-hello": "ignored"}}, "paths": {}}`, |
| 461 | FixedInstance: `{"swagger": "2.0", "info": {"title": "test", "version": "1.0", "license": {"name": "MIT"}}, "paths": {}}`, |
| 462 | }, |
| 463 | { |
| 464 | Name: "Contact with Vendor Extension", |
| 465 | BadInstance: `{"swagger": "2.0", "info": {"title": "test", "version": "1.0", "contact": {"name": "bill", "x-hello": "ignored"}}, "paths": {}}`, |
| 466 | FixedInstance: `{"swagger": "2.0", "info": {"title": "test", "version": "1.0", "contact": {"name": "bill"}}, "paths": {}}`, |
| 467 | }, |
| 468 | { |
| 469 | Name: "External Documentation with Vendor Extension", |
| 470 | BadInstance: `{"swagger": "2.0", "info": {"title": "test", "version": "1.0", "contact": {"name": "bill", "x-hello": "ignored"}}, "paths": {}}`, |
| 471 | FixedInstance: `{"swagger": "2.0", "info": {"title": "test", "version": "1.0", "contact": {"name": "bill"}}, "paths": {}}`, |
| 472 | }, |
| 473 | } |
| 474 | |
| 475 | for _, v := range patterns { |
| 476 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(v.Name, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 477 | bad, err := openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.ParseDocumentscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/ParseDocument().([]byte(v.BadInstance)) |
| 478 | if err != nil { |
| 479 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 480 | return |
| 481 | } |
| 482 | |
| 483 | fixed, err := openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.ParseDocumentscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/ParseDocument().([]byte(v.FixedInstance)) |
| 484 | if err != nil { |
| 485 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 486 | return |
| 487 | } |
| 488 | |
| 489 | badConverted := Swaggerscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#{} |
| 490 | if ok, err := badConverted.FromGnosticscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#FromGnostic().(bad); err != nil { |
| 491 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 492 | return |
| 493 | } else if ok { |
| 494 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("expected test to have data loss") |
| 495 | return |
| 496 | } |
| 497 | |
| 498 | fixedConverted := Swaggerscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#{} |
| 499 | if ok, err := fixedConverted.FromGnosticscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#FromGnostic().(fixed); err != nil { |
| 500 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 501 | return |
| 502 | } else if !ok { |
| 503 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("expected fixed test to not have data loss") |
| 504 | return |
| 505 | } |
| 506 | |
| 507 | // Convert JSON directly into our kube-openapi type and check that |
| 508 | // it is exactly equal to the converted instance |
| 509 | fixedDirect := Swaggerscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#{} |
| 510 | if err := jsonscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src go1.21 `encoding/json`/Unmarshal().([]byte(v.FixedInstance), &fixedDirect); err != nil { |
| 511 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 512 | return |
| 513 | } |
| 514 | |
| 515 | if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(fixedConverted, badConverted) { |
| 516 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("expected equal documents: %v", cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/Diff().(fixedConverted, badConverted, SwaggerDiffOptionsscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/SwaggerDiffOptions....)) |
| 517 | return |
| 518 | } |
| 519 | |
| 520 | // Make sure that they were exactly the same, except for the data loss |
| 521 | // by checking JSON encodes the some |
| 522 | badConvertedJSON, err := badConverted.MarshalJSONscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#MarshalJSON().() |
| 523 | if err != nil { |
| 524 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 525 | return |
| 526 | } |
| 527 | |
| 528 | fixedConvertedJSON, err := fixedConverted.MarshalJSONscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#MarshalJSON().() |
| 529 | if err != nil { |
| 530 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 531 | return |
| 532 | } |
| 533 | |
| 534 | fixedDirectJSON, err := fixedDirect.MarshalJSONscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#MarshalJSON().() |
| 535 | if err != nil { |
| 536 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 537 | return |
| 538 | } |
| 539 | |
| 540 | if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(badConvertedJSON, fixedConvertedJSON) { |
| 541 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("encoded json values for bad and fixed tests are not identical: %v", cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/Diff().(string(badConvertedJSON), string(fixedConvertedJSON))) |
| 542 | } |
| 543 | |
| 544 | if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(fixedDirectJSON, fixedConvertedJSON) { |
| 545 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("encoded json values for fixed direct and fixed-from-gnostic tests are not identical: %v", cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/Diff().(string(fixedDirectJSON), string(fixedConvertedJSON))) |
| 546 | } |
| 547 | }) |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | func TestBadStatusCodescip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec_test`/TestBadStatusCode().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 552 | const testCase = `{"swagger": "2.0", "info": {"title": "test", "version": "1.0"}, "paths": {"/": {"get": {"responses" : { "default": { "$ref": "#/definitions/a" }, "200": { "$ref": "#/definitions/b" }}}}}}` |
| 553 | const dropped = `{"swagger": "2.0", "info": {"title": "test", "version": "1.0"}, "paths": {"/": {"get": {"responses" : { "200": { "$ref": "#/definitions/b" }}}}}}` |
| 554 | gnosticInstance, err := openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.ParseDocumentscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/ParseDocument().([]byte(testCase)) |
| 555 | if err != nil { |
| 556 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 557 | } |
| 558 | |
| 559 | droppedGnosticInstance, err := openapi_v2scip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/.ParseDocumentscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/ParseDocument().([]byte(dropped)) |
| 560 | if err != nil { |
| 561 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 562 | } |
| 563 | |
| 564 | // Manually poke an response code name which gnostic's json parser would not allow |
| 565 | gnosticInstance.Pathsscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/Document#Paths..Pathscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/Paths#Path.[0].Valuescip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/NamedPathItem#Value..Getscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/PathItem#Get..Responsesscip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/Operation#Responses..ResponseCodescip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/Responses#ResponseCode.[0].Namescip-go gomod github.com/google/gnostic-models v0.6.9 `github.com/google/gnostic-models/openapiv2`/NamedResponseValue#Name. = "bad" |
| 566 | |
| 567 | badConverted := Swaggerscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#{} |
| 568 | droppedConverted := Swaggerscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#{} |
| 569 | |
| 570 | if ok, err := badConverted.FromGnosticscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#FromGnostic().(gnosticInstance); err != nil { |
| 571 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 572 | } else if ok { |
| 573 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("expected data loss converting an operation with a response code 'bad'") |
| 574 | } |
| 575 | |
| 576 | if ok, err := droppedConverted.FromGnosticscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#FromGnostic().(droppedGnosticInstance); err != nil { |
| 577 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 578 | } else if !ok { |
| 579 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("expected no data loss converting a known good operation") |
| 580 | } |
| 581 | |
| 582 | // Make sure that they were exactly the same, except for the data loss |
| 583 | // by checking JSON encodes the some |
| 584 | badConvertedJSON, err := badConverted.MarshalJSONscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#MarshalJSON().() |
| 585 | if err != nil { |
| 586 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 587 | return |
| 588 | } |
| 589 | |
| 590 | droppedConvertedJSON, err := droppedConverted.MarshalJSONscip-go gomod k8s.io/kube-openapi . `k8s.io/kube-openapi/pkg/validation/spec`/Swagger#MarshalJSON().() |
| 591 | if err != nil { |
| 592 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 593 | return |
| 594 | } |
| 595 | |
| 596 | if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(badConvertedJSON, droppedConvertedJSON) { |
| 597 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("encoded json values for bad and fixed tests are not identical: %v", cmpscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/.Diffscip-go gomod github.com/google/go-cmp v0.6.0 `github.com/google/go-cmp/cmp`/Diff().(string(badConvertedJSON), string(droppedConvertedJSON))) |
| 598 | } |
| 599 | } |