mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-08-08 23:37:11 +00:00
Update tests that depend on internal model names
Signed-off-by: Joe Betz <jpbetz@google.com>
This commit is contained in:
@@ -656,7 +656,7 @@ func TestGetDefinitionRefPrefix(t *testing.T) {
|
||||
// the first call to getDefinition
|
||||
|
||||
// ManagedFieldsEntry's Time field is known to use arefs
|
||||
managedFieldsTypePath := "k8s.io/apimachinery/pkg/apis/meta/v1.ManagedFieldsEntry"
|
||||
managedFieldsTypePath := "io.k8s.apimachinery.pkg.apis.meta.v1.ManagedFieldsEntry"
|
||||
|
||||
v2Ref := getDefinition(managedFieldsTypePath, true).SchemaProps.Properties["time"].SchemaProps.Ref
|
||||
v3Ref := getDefinition(managedFieldsTypePath, false).SchemaProps.Properties["time"].SchemaProps.Ref
|
||||
|
||||
@@ -414,12 +414,14 @@ func (t *testEnv) fetchOpenAPIOrDie() *spec.Swagger {
|
||||
}
|
||||
|
||||
func (t *testEnv) expectPath(swagger *spec.Swagger, path string) {
|
||||
t.t.Helper()
|
||||
if _, ok := swagger.Paths.Paths[path]; !ok {
|
||||
t.t.Errorf("Expected path %s to exist in OpenAPI", path)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *testEnv) expectNoPath(swagger *spec.Swagger, path string) {
|
||||
t.t.Helper()
|
||||
if _, ok := swagger.Paths.Paths[path]; ok {
|
||||
t.t.Errorf("Expected path %s to not exist in OpenAPI", path)
|
||||
}
|
||||
|
||||
@@ -42,12 +42,11 @@ func TestGetDefinitionName(t *testing.T) {
|
||||
// in production, the name is stripped of ".*vendor/" prefix before passed
|
||||
// to GetDefinitionName, so here typePkgName does not have the
|
||||
// "k8s.io/kubernetes/vendor" prefix.
|
||||
typePkgName := "k8s.io/apiserver/pkg/endpoints/openapi/testing.TestType"
|
||||
typeFriendlyName := "io.k8s.apiserver.pkg.endpoints.openapi.testing.TestType"
|
||||
s := runtime.NewScheme()
|
||||
s.AddKnownTypeWithName(testType.GroupVersionKind(), &testType)
|
||||
namer := NewDefinitionNamer(s)
|
||||
n, e := namer.GetDefinitionName(typePkgName)
|
||||
n, e := namer.GetDefinitionName(typeFriendlyName)
|
||||
assertEqual(t, typeFriendlyName, n)
|
||||
assertEqual(t, []interface{}{
|
||||
map[string]interface{}{
|
||||
@@ -56,7 +55,7 @@ func TestGetDefinitionName(t *testing.T) {
|
||||
"kind": "TestType",
|
||||
},
|
||||
}, e["x-kubernetes-group-version-kind"])
|
||||
n, e2 := namer.GetDefinitionName("test.com/another.Type")
|
||||
n, e2 := namer.GetDefinitionName("com.test.another.Type")
|
||||
assertEqual(t, "com.test.another.Type", n)
|
||||
assertEqual(t, e2, spec.Extensions(nil))
|
||||
}
|
||||
|
||||
@@ -39,10 +39,13 @@ import (
|
||||
auditinternal "k8s.io/apiserver/pkg/apis/audit"
|
||||
"k8s.io/apiserver/pkg/audit"
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
"k8s.io/apiserver/pkg/endpoints/openapi"
|
||||
apirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||
"k8s.io/apiserver/pkg/server/dynamiccertificates"
|
||||
clientscheme "k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
kubeopenapi "k8s.io/kube-openapi/pkg/common"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"golang.org/x/net/http2"
|
||||
@@ -1024,6 +1027,12 @@ func newClient(useNewConnection bool) *http.Client {
|
||||
}
|
||||
}
|
||||
|
||||
func getOpenAPIDefinitionsForTest(_ kubeopenapi.ReferenceCallback) map[string]kubeopenapi.OpenAPIDefinition {
|
||||
return map[string]kubeopenapi.OpenAPIDefinition{
|
||||
"io.k8s.apimachinery.pkg.apis.meta.v1.APIGroupList": {},
|
||||
}
|
||||
}
|
||||
|
||||
func newGenericAPIServer(t *testing.T, fAudit *fakeAudit, keepListening bool) *GenericAPIServer {
|
||||
config, _ := setUp(t)
|
||||
config.ShutdownDelayDuration = 100 * time.Millisecond
|
||||
@@ -1032,6 +1041,9 @@ func newGenericAPIServer(t *testing.T, fAudit *fakeAudit, keepListening bool) *G
|
||||
config.ShutdownWatchTerminationGracePeriod = 2 * time.Second
|
||||
config.AuditPolicyRuleEvaluator = fAudit
|
||||
config.AuditBackend = fAudit
|
||||
namer := openapi.NewDefinitionNamer(clientscheme.Scheme)
|
||||
config.OpenAPIConfig = DefaultOpenAPIConfig(getOpenAPIDefinitionsForTest, namer)
|
||||
config.OpenAPIV3Config = DefaultOpenAPIV3Config(getOpenAPIDefinitionsForTest, namer)
|
||||
|
||||
s, err := config.Complete(nil).New("test", NewEmptyDelegate())
|
||||
if err != nil {
|
||||
|
||||
@@ -119,11 +119,11 @@ func buildTestOpenAPIDefinition() kubeopenapi.OpenAPIDefinition {
|
||||
|
||||
func testGetOpenAPIDefinitions(_ kubeopenapi.ReferenceCallback) map[string]kubeopenapi.OpenAPIDefinition {
|
||||
return map[string]kubeopenapi.OpenAPIDefinition{
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1.Status": {},
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1.APIVersions": {},
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1.APIGroupList": {},
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1.APIGroup": buildTestOpenAPIDefinition(),
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1.APIResourceList": {},
|
||||
"io.k8s.apimachinery.pkg.apis.meta.v1.Status": {},
|
||||
"io.k8s.apimachinery.pkg.apis.meta.v1.APIVersions": {},
|
||||
"io.k8s.apimachinery.pkg.apis.meta.v1.APIGroupList": {},
|
||||
"io.k8s.apimachinery.pkg.apis.meta.v1.APIGroup": buildTestOpenAPIDefinition(),
|
||||
"io.k8s.apimachinery.pkg.apis.meta.v1.APIResourceList": {},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ func sendReq(t *testing.T, handler http.Handler, path string) []byte {
|
||||
|
||||
func getTestAPIServiceOpenAPIDefinitions(_ openapicommon.ReferenceCallback) map[string]openapicommon.OpenAPIDefinition {
|
||||
return map[string]openapicommon.OpenAPIDefinition{
|
||||
"k8s.io/kube-aggregator/pkg/apis/apiregistration/v1.APIService": buildTestAPIServiceOpenAPIDefinition(),
|
||||
"io.k8s.kube-aggregator.pkg.apis.apiregistration.v1.APIService": buildTestAPIServiceOpenAPIDefinition(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,6 @@ import (
|
||||
)
|
||||
|
||||
func TestEnablingOpenAPIEnumTypes(t *testing.T) {
|
||||
const typeToAddEnum = "k8s.io/api/core/v1.ContainerPort"
|
||||
const typeToCheckEnum = "io.k8s.api.core.v1.ContainerPort"
|
||||
|
||||
for _, tc := range []struct {
|
||||
@@ -60,7 +59,7 @@ func TestEnablingOpenAPIEnumTypes(t *testing.T) {
|
||||
|
||||
getDefinitionsFn := openapi.GetOpenAPIDefinitionsWithoutDisabledFeatures(func(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
|
||||
defs := generated.GetOpenAPIDefinitions(ref)
|
||||
def := defs[typeToAddEnum]
|
||||
def := defs[typeToCheckEnum]
|
||||
// replace protocol to add the would-be enum field.
|
||||
def.Schema.Properties["protocol"] = spec.Schema{
|
||||
SchemaProps: spec.SchemaProps{
|
||||
@@ -71,7 +70,7 @@ func TestEnablingOpenAPIEnumTypes(t *testing.T) {
|
||||
Enum: []interface{}{"SCTP", "TCP", "UDP"},
|
||||
},
|
||||
}
|
||||
defs[typeToAddEnum] = def
|
||||
defs[typeToCheckEnum] = def
|
||||
return defs
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user