Skip to content

Commit

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

* test manifest from string

* cl

* move cl

* update gha

* missed a line

* k8s 1.22

* fix test
  • Loading branch information
jenshu authored Jul 21, 2023
1 parent 36bee32 commit 8176b42
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
25 changes: 13 additions & 12 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,35 @@ on:
push:
branches:
- 'master'
- 'main'
pull_request:

env:
KUBE_VERSION: v1.22.15

jobs:
test:
name: Tests
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- name: Cancel Previous Runs
uses: styfle/cancel-workflow-action@0.4.0
uses: styfle/cancel-workflow-action@0.11.0
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go 1.18.2
uses: actions/setup-go@v1
uses: actions/setup-go@v4
with:
go-version: 1.18.2
- uses: actions/cache@v1
- uses: azure/setup-kubectl@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go
- uses: azure/setup-kubectl@v1
version: ${{ env.KUBE_VERSION }}
- name: Install kind
uses: helm/[email protected]
with:
version: 'v1.18.0'
- uses: engineerd/[email protected]
node_image: "kindest/node:${{ env.KUBE_VERSION }}"
- name: Run tests
run: |
go install github.com/onsi/ginkgo/[email protected] && export PATH=$PATH:$(go env GOPATH)/bin/
Expand Down
3 changes: 3 additions & 0 deletions changelog/v0.1.10/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.
2 changes: 1 addition & 1 deletion installutils/kuberesource/get_cluster_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ = Describe("GetClusterResources", func() {
Expect(err).NotTo(HaveOccurred())
expected := UnstructuredResources{expected1, expected2, expected3}

Expect(cmInOurNs).To(HaveLen(3))
Expect(cmInOurNs).To(HaveLen(3+1), "Expect our 3 ConfigMaps plus the default kube-root-ca.crt")
for i := range expected {
actual := cmInOurNs[i]
delete(actual.Object, "metadata")
Expand Down
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 8176b42

Please sign in to comment.