diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index ff27b7c..ec1a074 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -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/kind-action@v1.5.0 with: - version: 'v1.18.0' - - uses: engineerd/setup-kind@v0.5.0 + node_image: "kindest/node:${{ env.KUBE_VERSION }}" - name: Run tests run: | go install github.com/onsi/ginkgo/ginkgo@v1.16 && export PATH=$PATH:$(go env GOPATH)/bin/ diff --git a/changelog/v0.1.10/test-manifest.yaml b/changelog/v0.1.10/test-manifest.yaml new file mode 100644 index 0000000..e080967 --- /dev/null +++ b/changelog/v0.1.10/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/installutils/kuberesource/get_cluster_resources_test.go b/installutils/kuberesource/get_cluster_resources_test.go index 7167092..26bcb41 100644 --- a/installutils/kuberesource/get_cluster_resources_test.go +++ b/installutils/kuberesource/get_cluster_resources_test.go @@ -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") diff --git a/manifesttestutils/util.go b/manifesttestutils/util.go index 10a91fe..2c31541 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