Skip to content

Commit

Permalink
Test manifest from string [v0.3.x] (#39)
Browse files Browse the repository at this point in the history
* Test manifest from string (#38)

* test manifest from string

* cl

* move cl
  • Loading branch information
jenshu authored Jul 21, 2023
1 parent 767d2c9 commit ac440c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog/v0.3.2/test-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
changelog:
- type: NON_USER_FACING
description: Add new constructor (NewTestManifestFromYaml) that creates a TestManifest from a yaml string.
17 changes: 15 additions & 2 deletions manifesttestutils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ac440c6

Please sign in to comment.