Skip to content

Commit

Permalink
Merge pull request #4773 from natasha41575/openapitests
Browse files Browse the repository at this point in the history
run openapi tests with other krusty tests
  • Loading branch information
k8s-ci-robot authored Aug 26, 2022
2 parents 2e2674f + 08918ea commit a8388f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 68 deletions.
1 change: 0 additions & 1 deletion api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ./...
Expand Down
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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))
}

Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

0 comments on commit a8388f4

Please sign in to comment.