From ac440c6c49b2e9bac4ea12fb97e54e880a5ffe25 Mon Sep 17 00:00:00 2001 From: Jenny Shu <28537278+jenshu@users.noreply.github.com> Date: Fri, 21 Jul 2023 10:51:04 -0400 Subject: [PATCH] Test manifest from string [v0.3.x] (#39) * Test manifest from string (#38) * test manifest from string * cl * move cl --- changelog/v0.3.2/test-manifest.yaml | 3 +++ manifesttestutils/util.go | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 changelog/v0.3.2/test-manifest.yaml diff --git a/changelog/v0.3.2/test-manifest.yaml b/changelog/v0.3.2/test-manifest.yaml new file mode 100644 index 0000000..e080967 --- /dev/null +++ b/changelog/v0.3.2/test-manifest.yaml @@ -0,0 +1,3 @@ +changelog: + - type: NON_USER_FACING + description: Add new constructor (NewTestManifestFromYaml) that creates a TestManifest from a yaml string. \ No newline at end of file diff --git a/manifesttestutils/util.go b/manifesttestutils/util.go index a9513a9..44582f3 100644 --- a/manifesttestutils/util.go +++ b/manifesttestutils/util.go @@ -59,12 +59,21 @@ type testManifest struct { resources kuberesource.UnstructuredResources } +// NewTestManifest creates a TestManifest by reading from the manifest file located at `relativePathToManifest`. func NewTestManifest(relativePathToManifest string) TestManifest { return &testManifest{ - resources: mustGetResources(relativePathToManifest), + resources: mustGetResourcesFromFile(relativePathToManifest), } } +// NewTestManifestFromYaml creates a TestManifest from the given manifest yaml. +func NewTestManifestFromYaml(manifest string) TestManifest { + return &testManifest{ + resources: mustGetResourcesFromYaml(manifest), + } +} + +// NewTestManifestWithResources creates a TestManifest with the given resources. func NewTestManifestWithResources(resources kuberesource.UnstructuredResources) TestManifest { return &testManifest{ resources: resources, @@ -308,8 +317,12 @@ var ( yamlSeparator = regexp.MustCompile("\n---") ) -func mustGetResources(relativePathToManifest string) kuberesource.UnstructuredResources { +func mustGetResourcesFromFile(relativePathToManifest string) kuberesource.UnstructuredResources { manifest := mustReadManifest(relativePathToManifest) + return mustGetResourcesFromYaml(manifest) +} + +func mustGetResourcesFromYaml(manifest string) kuberesource.UnstructuredResources { snippets := yamlSeparator.Split(manifest, -1) var resources kuberesource.UnstructuredResources