From 188208880965ffa1bfb6c3e07abeb0ece4b71682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Bezerra?= Date: Tue, 19 Apr 2022 23:54:09 -0300 Subject: [PATCH] Add tests for remote OpenAPI schema --- api/krusty/openapicustomschema_test.go | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/api/krusty/openapicustomschema_test.go b/api/krusty/openapicustomschema_test.go index 0e1844250a3..36a55ecfb07 100644 --- a/api/krusty/openapicustomschema_test.go +++ b/api/krusty/openapicustomschema_test.go @@ -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(".", ` @@ -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", ` @@ -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()