From 08918ea352be5e2639656d1e07db1a4eb66740e5 Mon Sep 17 00:00:00 2001 From: natasha41575 Date: Thu, 25 Aug 2022 16:13:36 -0500 Subject: [PATCH] run openapi tests with other krusty tests --- api/Makefile | 1 - .../openapicustomschema_test.go | 72 ++----------------- 2 files changed, 5 insertions(+), 68 deletions(-) rename api/krusty/{openapitests => }/openapicustomschema_test.go (90%) diff --git a/api/Makefile b/api/Makefile index a19cd0e75..6a4ce1ed6 100644 --- a/api/Makefile +++ b/api/Makefile @@ -5,7 +5,6 @@ include ../Makefile-modules.mk test: go test -v -timeout 45m -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222" - cd krusty/openapitests; OPENAPI_TEST=true go test -v -timeout 45m -p 1 -cover ./... build: go build -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222" ./... diff --git a/api/krusty/openapitests/openapicustomschema_test.go b/api/krusty/openapicustomschema_test.go similarity index 90% rename from api/krusty/openapitests/openapicustomschema_test.go rename to api/krusty/openapicustomschema_test.go index 95a767dc8..791ed6f8d 100644 --- a/api/krusty/openapitests/openapicustomschema_test.go +++ b/api/krusty/openapicustomschema_test.go @@ -1,12 +1,9 @@ // Copyright 2019 The Kubernetes Authors. // SPDX-License-Identifier: Apache-2.0 -// The openapi field tests are separated due to the global OpenAPI variable causing -// race conditions. As a result, these tests can't be run in parallel with the other tests. -package openapitests //nolint +package krusty_test import ( - "fmt" "os" "testing" @@ -17,12 +14,12 @@ import ( ) func writeTestSchema(th kusttest_test.Harness, filepath string) { - bytes, _ := os.ReadFile("../testdata/customschema.json") + bytes, _ := os.ReadFile("./testdata/customschema.json") th.WriteF(filepath+"mycrd_schema.json", string(bytes)) } func writeTestSchemaYaml(th kusttest_test.Harness, filepath string) { - bytes, _ := os.ReadFile("../testdata/customschema.yaml") + bytes, _ := os.ReadFile("./testdata/customschema.yaml") th.WriteF(filepath+"mycrd_schema.yaml", string(bytes)) } @@ -144,9 +141,7 @@ spec: func runOpenApiTest(t *testing.T, test func(t *testing.T)) { t.Helper() - if val, ok := os.LookupEnv("OPENAPI_TEST"); !ok || val != "true" { - t.SkipNow() - } + openapi.ResetOpenAPI() test(t) openapi.ResetOpenAPI() } @@ -485,7 +480,7 @@ spec: `) // openapi schema referred to by the component - bytes, _ := os.ReadFile("../testdata/openshiftschema.json") + bytes, _ := os.ReadFile("./testdata/openshiftschema.json") th.WriteF("components/dc-openapi/openapi.json", string(bytes)) // patch referred to by the component @@ -647,60 +642,3 @@ spec: assert.Equal(t, kubernetesapi.DefaultOpenAPI, openapi.GetSchemaVersion()) }) } - -// The following definitions are copied from the krusty package. - -type FileGen func(kusttest_test.Harness) - -func writeTestBase(th kusttest_test.Harness) { - th.WriteK("base", ` -resources: -- deploy.yaml -configMapGenerator: -- name: my-configmap - literals: - - testValue=purple - - otherValue=green -`) - th.WriteF("base/deploy.yaml", ` -apiVersion: v1 -kind: Deployment -metadata: - name: storefront -spec: - replicas: 1 -`) -} - -func writeOverlayProd(th kusttest_test.Harness) { - th.WriteK("prod", ` -resources: -- ../base -- db - -components: -- ../comp -`) - writeDB(th) -} - -func writeDB(th kusttest_test.Harness) { - deployment("db", "prod/db")(th) -} - -func deployment(name string, path string) FileGen { - return writeF(path, fmt.Sprintf(` -apiVersion: v1 -kind: Deployment -metadata: - name: %s -spec: - type: Logical -`, name)) -} - -func writeF(path string, content string) FileGen { - return func(th kusttest_test.Harness) { - th.WriteF(path, content) - } -}