Skip to content

Commit

Permalink
Add tests for remote OpenAPI schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mvgmb committed Apr 20, 2022
1 parent 5d3053d commit 1882088
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions api/krusty/openapicustomschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ openapi:
th.AssertActualEqualsExpected(m, patchedCustomResource)
}

func TestCustomOpenApiFieldBasicUsageWithRemoteSchema(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
resources:
- mycrd.yaml
openapi:
path: https://github.com/kubernetes-sigs/kustomize/raw/master/api/krusty/testdata/customschema.json
`+customSchemaPatch)
writeCustomResource(th, "mycrd.yaml")
writeTestSchema(th, "./")
openapi.ResetOpenAPI()
m := th.Run(".", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, patchedCustomResource)
}

func TestCustomOpenApiFieldWithTwoGvks(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK(".", `
Expand Down Expand Up @@ -278,6 +293,27 @@ resources:
openapi.GetSchemaVersion())
}

func TestCustomOpenApiFieldFromBaseWithRemoteSchema(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("base", `
resources:
- mycrd.yaml
openapi:
path: https://github.com/kubernetes-sigs/kustomize/raw/master/api/krusty/testdata/customschema.json
`)
th.WriteK("overlay", `
resources:
- ../base
`+customSchemaPatch)
writeCustomResource(th, "base/mycrd.yaml")
writeTestSchema(th, "base/")
openapi.ResetOpenAPI()
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, patchedCustomResource)
assert.Equal(t, "using custom schema from file provided",
openapi.GetSchemaVersion())
}

func TestCustomOpenApiFieldFromOverlay(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("base", `
Expand All @@ -299,6 +335,27 @@ openapi:
openapi.GetSchemaVersion())
}

func TestCustomOpenApiFieldFromOverlayWithRemoteSchema(t *testing.T) {
th := kusttest_test.MakeHarness(t)
th.WriteK("base", `
resources:
- mycrd.yaml
`)
th.WriteK("overlay", `
resources:
- ../base
openapi:
path: https://github.com/kubernetes-sigs/kustomize/raw/master/api/krusty/testdata/customschema.json
`+customSchemaPatch)
writeCustomResource(th, "base/mycrd.yaml")
writeTestSchema(th, "overlay/")
openapi.ResetOpenAPI()
m := th.Run("overlay", th.MakeDefaultOptions())
th.AssertActualEqualsExpected(m, patchedCustomResource)
assert.Equal(t, "using custom schema from file provided",
openapi.GetSchemaVersion())
}

func TestCustomOpenApiFieldOverlayTakesPrecedence(t *testing.T) {
th := kusttest_test.MakeHarness(t)
openapi.ResetOpenAPI()
Expand Down

0 comments on commit 1882088

Please sign in to comment.