From d49e5aa5aa34aceb48aced0cabc92df7410a8166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rio=20Bezerra?= Date: Wed, 20 Apr 2022 00:03:22 -0300 Subject: [PATCH] Add tests for remote OpenAPI schema --- .../openapitests/openapicustomschema_test.go | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/api/krusty/openapitests/openapicustomschema_test.go b/api/krusty/openapitests/openapicustomschema_test.go index 91f70cc827..fb196df778 100644 --- a/api/krusty/openapitests/openapicustomschema_test.go +++ b/api/krusty/openapitests/openapicustomschema_test.go @@ -170,6 +170,23 @@ openapi: }) } +func TestCustomOpenApiFieldBasicUsageWithRemoteSchema(t *testing.T) { + runOpenApiTest(t, func(t *testing.T) { + t.Helper() + 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, "./") + m := th.Run(".", th.MakeDefaultOptions()) + th.AssertActualEqualsExpected(m, patchedCustomResource) + }) +} + func TestCustomOpenApiFieldWithTwoGvks(t *testing.T) { runOpenApiTest(t, func(t *testing.T) { t.Helper() @@ -303,6 +320,29 @@ resources: }) } +func TestCustomOpenApiFieldFromBaseWithRemoteSchema(t *testing.T) { + runOpenApiTest(t, func(t *testing.T) { + t.Helper() + 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/") + 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) { runOpenApiTest(t, func(t *testing.T) { t.Helper() @@ -326,6 +366,29 @@ openapi: }) } +func TestCustomOpenApiFieldFromOverlayWithRemoteSchema(t *testing.T) { + runOpenApiTest(t, func(t *testing.T) { + t.Helper() + 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/") + 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) { runOpenApiTest(t, func(t *testing.T) { t.Helper()