From 843827baf38dd5fcd9c94946c3b7ee621d927811 Mon Sep 17 00:00:00 2001 From: David Gannon <19214156+dgannon991@users.noreply.github.com> Date: Wed, 1 Jan 2025 15:42:33 +0000 Subject: [PATCH] WIP: Moved all tests to integration Signed-off-by: David Gannon <19214156+dgannon991@users.noreply.github.com> --- .github/workflows/porter-integration-pr.yml | 10 +-- .../workflows/porter-integration-release.yml | 10 +-- pkg/porter/build.go | 2 +- pkg/porter/generateManifest.go | 4 +- pkg/porter/generateManifest_test.go | 6 +- .../integration}/build_integration_test.go | 77 ++++++++--------- .../integration}/pkgmgmt_integration_test.go | 7 +- .../integration}/runner_integration_test.go | 7 +- .../integration}/testdata/exec_input.yaml | 0 .../testdata/exec_input_with_whitespace.yaml | 0 .../integration}/testdata/paramafest.yaml | 0 .../testdata/porter-with-image-tag.yaml | 0 tests/integration/testdata/porter.yaml | 82 +++++++++++++++++++ 13 files changed, 139 insertions(+), 66 deletions(-) rename {pkg/porter => tests/integration}/build_integration_test.go (83%) rename {pkg/mixin => tests/integration}/pkgmgmt_integration_test.go (77%) rename {pkg/pkgmgmt/client => tests/integration}/runner_integration_test.go (90%) rename {pkg/pkgmgmt/client => tests/integration}/testdata/exec_input.yaml (100%) rename {pkg/pkgmgmt/client => tests/integration}/testdata/exec_input_with_whitespace.yaml (100%) rename {pkg/porter => tests/integration}/testdata/paramafest.yaml (100%) rename {pkg/porter => tests/integration}/testdata/porter-with-image-tag.yaml (100%) create mode 100644 tests/integration/testdata/porter.yaml diff --git a/.github/workflows/porter-integration-pr.yml b/.github/workflows/porter-integration-pr.yml index ba1f30937..da8206020 100644 --- a/.github/workflows/porter-integration-pr.yml +++ b/.github/workflows/porter-integration-pr.yml @@ -241,7 +241,7 @@ jobs: shell: bash - name: Integration Test env: - PORTER_INTEG_FILE: ../../pkg/porter/build_integration_test.go + PORTER_INTEG_FILE: build_integration_test.go run: go run mage.go -v TestIntegration shell: bash lifecycle_integration_test: @@ -274,7 +274,7 @@ jobs: PORTER_INTEG_FILE: lifecycle_integration_test.go run: go run mage.go -v TestIntegration shell: bash - pkg_mixin_pkgmgmt_integration_test: + pkgmgmt_integration_test: runs-on: ubuntu-latest steps: - name: checkout @@ -301,10 +301,10 @@ jobs: shell: bash - name: Integration Test env: - PORTER_INTEG_FILE: ../../pkg/mixin/pkgmgmt_integration_test.go + PORTER_INTEG_FILE: pkgmgmt_integration_test.go run: go run mage.go -v TestIntegration shell: bash - pkg_pkgmgmt_client_runner_integration_test: + runner_integration_test: runs-on: ubuntu-latest steps: - name: checkout @@ -331,7 +331,7 @@ jobs: shell: bash - name: Integration Test env: - PORTER_INTEG_FILE: ../../pkg/pkgmgmt/client/runner_integration_test.go + PORTER_INTEG_FILE: runner_integration_test.go run: go run mage.go -v TestIntegration shell: bash agent_integration_test: diff --git a/.github/workflows/porter-integration-release.yml b/.github/workflows/porter-integration-release.yml index cc045f9fe..7ce76c148 100644 --- a/.github/workflows/porter-integration-release.yml +++ b/.github/workflows/porter-integration-release.yml @@ -280,7 +280,7 @@ jobs: shell: bash - name: Integration Test env: - PORTER_INTEG_FILE: ../../pkg/porter/build_integration_test.go + PORTER_INTEG_FILE: build_integration_test.go run: go run mage.go -v TestIntegration shell: bash lifecycle_integration_test: @@ -313,7 +313,7 @@ jobs: PORTER_INTEG_FILE: lifecycle_integration_test.go run: go run mage.go -v TestIntegration shell: bash - pkg_mixin_pkgmgmt_integration_test: + pkgmgmt_integration_test: runs-on: ubuntu-latest steps: - name: checkout @@ -340,10 +340,10 @@ jobs: shell: bash - name: Integration Test env: - PORTER_INTEG_FILE: ../../pkg/mixin/pkgmgmt_integration_test.go + PORTER_INTEG_FILE: pkgmgmt_integration_test.go run: go run mage.go -v TestIntegration shell: bash - pkg_pkgmgmt_client_runner_integration_test: + runner_integration_test: runs-on: ubuntu-latest steps: - name: checkout @@ -370,7 +370,7 @@ jobs: shell: bash - name: Integration Test env: - PORTER_INTEG_FILE: ../../pkg/pkgmgmt/client/runner_integration_test.go + PORTER_INTEG_FILE: runner_integration_test.go run: go run mage.go -v TestIntegration shell: bash agent_integration_test: diff --git a/pkg/porter/build.go b/pkg/porter/build.go index 1d8bea1ec..a2c00c568 100644 --- a/pkg/porter/build.go +++ b/pkg/porter/build.go @@ -23,7 +23,7 @@ import ( type BuildOptions struct { BundleDefinitionOptions - metadataOpts + MetadataOpts build.BuildImageOptions // NoLint indicates if lint should be run before build. diff --git a/pkg/porter/generateManifest.go b/pkg/porter/generateManifest.go index c119a23eb..4343da91a 100644 --- a/pkg/porter/generateManifest.go +++ b/pkg/porter/generateManifest.go @@ -21,9 +21,9 @@ import ( "go.opentelemetry.io/otel/attribute" ) -// metadataOpts contain manifest fields eligible for dynamic +// MetadataOpts contain manifest fields eligible for dynamic // updating prior to saving Porter's internal version of the manifest -type metadataOpts struct { +type MetadataOpts struct { Name string Version string } diff --git a/pkg/porter/generateManifest_test.go b/pkg/porter/generateManifest_test.go index 3427e984f..74b9ba2b7 100644 --- a/pkg/porter/generateManifest_test.go +++ b/pkg/porter/generateManifest_test.go @@ -42,15 +42,15 @@ func Test_generateInternalManifest(t *testing.T) { wantManifest: "expected-result.yaml", }, { name: "name set", - opts: BuildOptions{metadataOpts: metadataOpts{Name: "newname"}}, + opts: BuildOptions{MetadataOpts: MetadataOpts{Name: "newname"}}, wantManifest: "new-name.yaml", }, { name: "version set", - opts: BuildOptions{metadataOpts: metadataOpts{Version: "1.0.0"}}, + opts: BuildOptions{MetadataOpts: MetadataOpts{Version: "1.0.0"}}, wantManifest: "new-version.yaml", }, { name: "name and value set", - opts: BuildOptions{metadataOpts: metadataOpts{Name: "newname", Version: "1.0.0"}}, + opts: BuildOptions{MetadataOpts: MetadataOpts{Name: "newname", Version: "1.0.0"}}, wantManifest: "all-fields.yaml", }, { name: "custom input set", diff --git a/pkg/porter/build_integration_test.go b/tests/integration/build_integration_test.go similarity index 83% rename from pkg/porter/build_integration_test.go rename to tests/integration/build_integration_test.go index b08c6376c..467c5ca28 100644 --- a/pkg/porter/build_integration_test.go +++ b/tests/integration/build_integration_test.go @@ -1,6 +1,6 @@ //go:build integration -package porter +package integration import ( "context" @@ -15,6 +15,7 @@ import ( "get.porter.sh/porter/pkg/linter" "get.porter.sh/porter/pkg/manifest" "get.porter.sh/porter/pkg/mixin" + "get.porter.sh/porter/pkg/porter" "get.porter.sh/porter/pkg/schema" "get.porter.sh/porter/pkg/yaml" "get.porter.sh/porter/tests" @@ -24,7 +25,7 @@ import ( ) func TestPorter_Build(t *testing.T) { - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() configTpl, err := p.Templates.GetManifest() @@ -37,7 +38,7 @@ func TestPorter_Build(t *testing.T) { junkExists, _ := p.FileSystem.DirExists(junkDir) assert.True(t, junkExists, "failed to create junk files for the test") - opts := BuildOptions{} + opts := porter.BuildOptions{} require.NoError(t, opts.Validate(p.Porter), "Validate failed") err = p.Build(context.Background(), opts) @@ -106,7 +107,7 @@ func TestPorter_Build_ChecksManifestSchemaVersion(t *testing.T) { } for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() // Make a bundle with the specified schemaVersion @@ -116,7 +117,7 @@ func TestPorter_Build_ChecksManifestSchemaVersion(t *testing.T) { require.NoError(t, e.SetValue("schemaVersion", tc.schemaVersion)) require.NoError(t, e.WriteFile("porter.yaml")) - opts := BuildOptions{} + opts := porter.BuildOptions{} opts.File = "porter.yaml" err := p.Build(context.Background(), opts) if tc.wantErr == "" { @@ -138,7 +139,7 @@ func TestPorter_LintDuringBuild(t *testing.T) { } t.Run("failing lint should stop build", func(t *testing.T) { - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() testMixins := p.Mixins.(*mixin.TestMixinProvider) @@ -147,7 +148,7 @@ func TestPorter_LintDuringBuild(t *testing.T) { err := p.Create() require.NoError(t, err, "Create failed") - opts := BuildOptions{NoLint: false} + opts := porter.BuildOptions{NoLint: false} err = opts.Validate(p.Porter) require.NoError(t, err) @@ -157,7 +158,7 @@ func TestPorter_LintDuringBuild(t *testing.T) { }) t.Run("ignores lint error with --no-lint", func(t *testing.T) { - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() testMixins := p.Mixins.(*mixin.TestMixinProvider) @@ -166,7 +167,7 @@ func TestPorter_LintDuringBuild(t *testing.T) { err := p.Create() require.NoError(t, err, "Create failed") - opts := BuildOptions{NoLint: true} + opts := porter.BuildOptions{NoLint: true} err = opts.Validate(p.Porter) require.NoError(t, err) @@ -177,17 +178,16 @@ func TestPorter_LintDuringBuild(t *testing.T) { } func TestPorter_paramRequired(t *testing.T) { - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() p.TestConfig.TestContext.AddTestFile("./testdata/paramafest.yaml", config.Name) ctx := context.Background() - m, err := manifest.LoadManifestFrom(ctx, p.Config, config.Name) - require.NoError(t, err) + opts := porter.BuildOptions{} + require.NoError(t, opts.Validate(p.Porter), "Validate failed") - err = p.buildBundle(ctx, m, "digest", false) - require.NoError(t, err) + err := p.Build(ctx, opts) bundleBytes, err := p.FileSystem.ReadFile(build.LOCAL_BUNDLE) require.NoError(t, err) @@ -201,44 +201,44 @@ func TestPorter_paramRequired(t *testing.T) { } func TestBuildOptions_Validate(t *testing.T) { - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() p.TestConfig.TestContext.AddTestFile("./testdata/porter.yaml", config.Name) testcases := []struct { name string - opts BuildOptions + opts porter.BuildOptions wantDriver string wantError string }{{ name: "no opts", - opts: BuildOptions{}, + opts: porter.BuildOptions{}, wantDriver: config.BuildDriverBuildkit, }, { name: "invalid version set - latest", - opts: BuildOptions{metadataOpts: metadataOpts{Version: "latest"}}, + opts: porter.BuildOptions{MetadataOpts: porter.MetadataOpts{Version: "latest"}}, wantError: `invalid bundle version: "latest" is not a valid semantic version`, }, { name: "valid version - v prefix", - opts: BuildOptions{metadataOpts: metadataOpts{Version: "v1.0.0"}}, + opts: porter.BuildOptions{MetadataOpts: porter.MetadataOpts{Version: "v1.0.0"}}, }, { name: "valid version - with hash", - opts: BuildOptions{metadataOpts: metadataOpts{Version: "v0.1.7+58d98af56c3a4c40c69535654216bd4a1fa701e7"}}, + opts: porter.BuildOptions{MetadataOpts: porter.MetadataOpts{Version: "v0.1.7+58d98af56c3a4c40c69535654216bd4a1fa701e7"}}, }, { name: "valid name and value set", - opts: BuildOptions{metadataOpts: metadataOpts{Name: "newname", Version: "1.0.0"}}, + opts: porter.BuildOptions{MetadataOpts: porter.MetadataOpts{Name: "newname", Version: "1.0.0"}}, }, { name: "deprecated driver: docker", - opts: BuildOptions{Driver: config.BuildDriverDocker}, + opts: porter.BuildOptions{Driver: config.BuildDriverDocker}, wantError: `invalid --driver value docker`, }, { name: "valid driver: buildkit", - opts: BuildOptions{Driver: config.BuildDriverBuildkit}, + opts: porter.BuildOptions{Driver: config.BuildDriverBuildkit}, wantDriver: config.BuildDriverBuildkit, }, { name: "invalid driver", - opts: BuildOptions{Driver: "missing-driver"}, + opts: porter.BuildOptions{Driver: "missing-driver"}, wantError: `invalid --driver value missing-driver`, }} @@ -259,13 +259,13 @@ func TestBuildOptions_Validate(t *testing.T) { } func TestBuildOptions_Defaults(t *testing.T) { - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() p.TestConfig.TestContext.AddTestFile("./testdata/porter.yaml", config.Name) t.Run("default driver", func(t *testing.T) { - opts := BuildOptions{} + opts := porter.BuildOptions{} err := opts.Validate(p.Porter) require.NoError(t, err, "Validate failed") assert.Equal(t, config.BuildDriverBuildkit, opts.Driver) @@ -273,22 +273,17 @@ func TestBuildOptions_Defaults(t *testing.T) { } func TestPorter_BuildWithCustomValues(t *testing.T) { - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() p.TestConfig.TestContext.AddTestFile("./testdata/porter.yaml", config.Name) ctx := context.Background() - m, err := manifest.LoadManifestFrom(ctx, p.Config, config.Name) - require.NoError(t, err) - - err = p.buildBundle(ctx, m, "digest", false) - require.NoError(t, err) - opts := BuildOptions{Customs: []string{"customKey1=editedCustomValue1"}} + opts := porter.BuildOptions{Customs: []string{"customKey1=editedCustomValue1"}} require.NoError(t, opts.Validate(p.Porter), "Validate failed") - err = p.Build(ctx, opts) + err := p.Build(ctx, opts) require.NoError(t, err) bun, err := p.CNAB.LoadBundle(build.LOCAL_BUNDLE) @@ -298,26 +293,20 @@ func TestPorter_BuildWithCustomValues(t *testing.T) { } func TestPorter_BuildWithPreserveTags(t *testing.T) { - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() p.TestConfig.TestContext.AddTestFile("./testdata/porter-with-image-tag.yaml", config.Name) ctx := context.Background() - m, err := manifest.LoadManifestFrom(ctx, p.Config, config.Name) - require.NoError(t, err) - - err = p.buildBundle(ctx, m, "digest", true) - require.NoError(t, err) - - opts := BuildOptions{ - BundleDefinitionOptions: BundleDefinitionOptions{ + opts := porter.BuildOptions{ + BundleDefinitionOptions: porter.BundleDefinitionOptions{ PreserveTags: true, }, } require.NoError(t, opts.Validate(p.Porter), "Validate failed") - err = p.Build(ctx, opts) + err := p.Build(ctx, opts) require.NoError(t, err) bun, err := p.CNAB.LoadBundle(build.LOCAL_BUNDLE) diff --git a/pkg/mixin/pkgmgmt_integration_test.go b/tests/integration/pkgmgmt_integration_test.go similarity index 77% rename from pkg/mixin/pkgmgmt_integration_test.go rename to tests/integration/pkgmgmt_integration_test.go index ddd159508..c4876a535 100644 --- a/pkg/mixin/pkgmgmt_integration_test.go +++ b/tests/integration/pkgmgmt_integration_test.go @@ -1,6 +1,6 @@ //go:build integration -package mixin +package integration import ( "context" @@ -8,6 +8,7 @@ import ( "testing" "get.porter.sh/porter/pkg/config" + "get.porter.sh/porter/pkg/mixin" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -22,11 +23,11 @@ func TestPackageManager_GetSchema(t *testing.T) { binDir := c.TestContext.FindBinDir() c.SetHomeDir(binDir) - p := NewPackageManager(c.Config) + p := mixin.NewPackageManager(c.Config) gotSchema, err := p.GetSchema(ctx, "exec") require.NoError(t, err) - wantSchema, err := os.ReadFile("../exec/schema/exec.json") + wantSchema, err := os.ReadFile("../../pkg/exec/schema/exec.json") require.NoError(t, err) assert.Equal(t, string(wantSchema), gotSchema) } diff --git a/pkg/pkgmgmt/client/runner_integration_test.go b/tests/integration/runner_integration_test.go similarity index 90% rename from pkg/pkgmgmt/client/runner_integration_test.go rename to tests/integration/runner_integration_test.go index cb1ba508a..33756497b 100644 --- a/pkg/pkgmgmt/client/runner_integration_test.go +++ b/tests/integration/runner_integration_test.go @@ -1,6 +1,6 @@ //go:build integration -package client +package integration import ( "bytes" @@ -10,6 +10,7 @@ import ( "testing" "get.porter.sh/porter/pkg/pkgmgmt" + "get.porter.sh/porter/pkg/pkgmgmt/client" "get.porter.sh/porter/pkg/portercontext" "get.porter.sh/porter/pkg/test" "get.porter.sh/porter/tests" @@ -27,7 +28,7 @@ func TestRunner_Run(t *testing.T) { binDir := c.FindBinDir() // I'm not using the TestRunner because I want to use the current filesystem, not an isolated one - r := NewRunner("exec", filepath.Join(binDir, "mixins/exec"), false) + r := client.NewRunner("exec", filepath.Join(binDir, "mixins/exec"), false) // Capture the output r.Out = output @@ -66,7 +67,7 @@ func TestRunner_RunWithMaskedOutput(t *testing.T) { binDir := c.FindBinDir() // I'm not using the TestRunner because I want to use the current filesystem, not an isolated one - r := NewRunner("exec", filepath.Join(binDir, "mixins/exec"), false) + r := client.NewRunner("exec", filepath.Join(binDir, "mixins/exec"), false) // Capture the output r.Out = censoredWriter diff --git a/pkg/pkgmgmt/client/testdata/exec_input.yaml b/tests/integration/testdata/exec_input.yaml similarity index 100% rename from pkg/pkgmgmt/client/testdata/exec_input.yaml rename to tests/integration/testdata/exec_input.yaml diff --git a/pkg/pkgmgmt/client/testdata/exec_input_with_whitespace.yaml b/tests/integration/testdata/exec_input_with_whitespace.yaml similarity index 100% rename from pkg/pkgmgmt/client/testdata/exec_input_with_whitespace.yaml rename to tests/integration/testdata/exec_input_with_whitespace.yaml diff --git a/pkg/porter/testdata/paramafest.yaml b/tests/integration/testdata/paramafest.yaml similarity index 100% rename from pkg/porter/testdata/paramafest.yaml rename to tests/integration/testdata/paramafest.yaml diff --git a/pkg/porter/testdata/porter-with-image-tag.yaml b/tests/integration/testdata/porter-with-image-tag.yaml similarity index 100% rename from pkg/porter/testdata/porter-with-image-tag.yaml rename to tests/integration/testdata/porter-with-image-tag.yaml diff --git a/tests/integration/testdata/porter.yaml b/tests/integration/testdata/porter.yaml new file mode 100644 index 000000000..4189a05e4 --- /dev/null +++ b/tests/integration/testdata/porter.yaml @@ -0,0 +1,82 @@ +schemaVersion: 1.0.0 +name: porter-hello +version: 0.1.0 +description: "A bundle with a custom action" +registry: "localhost:5000" + +custom: + customKey1: "customValue1" + +credentials: + - name: my-first-cred + env: MY_FIRST_CRED + - name: my-second-cred + description: "My second cred" + path: /path/to/my-second-cred + +images: + something: + description: "an image" + imageType: "docker" + repository: "getporter/boo" + digest: "sha256:6b5a28ccbb76f12ce771a23757880c6083234255c5ba191fca1c5db1f71c1687" + +parameters: + - name: my-first-param + type: integer + default: 9 + env: MY_FIRST_PARAM + applyTo: + - "install" + - name: my-second-param + description: "My second parameter" + type: string + default: spring-music-demo + path: /path/to/my-second-param + sensitive: true + +outputs: + - name: my-first-output + type: string + applyTo: + - "install" + - "upgrade" + sensitive: true + - name: my-second-output + description: "My second output" + type: boolean + sensitive: false + - name: kubeconfig + type: file + path: /home/nonroot/.kube/config + +mixins: + - exec + +install: + - exec: + description: "Install Hello World with custom arguments" + command: echo + arguments: + - ${ bundle.custom.customKey1 } + +upgrade: + - exec: + description: "World 2.0" + command: bash + flags: + c: echo World 2.0 + +zombies: + - exec: + description: "Trigger zombie apocalypse" + command: bash + flags: + c: echo oh noes my brains + +uninstall: + - exec: + description: "Uninstall Hello World" + command: bash + flags: + c: echo Goodbye World