diff --git a/.github/workflows/porter-integration-pr.yml b/.github/workflows/porter-integration-pr.yml index c084c2c74..ba1f30937 100644 --- a/.github/workflows/porter-integration-pr.yml +++ b/.github/workflows/porter-integration-pr.yml @@ -244,7 +244,7 @@ jobs: PORTER_INTEG_FILE: ../../pkg/porter/build_integration_test.go run: go run mage.go -v TestIntegration shell: bash - porter_lifecycle_integration_test: + lifecycle_integration_test: runs-on: ubuntu-latest steps: - name: checkout @@ -271,7 +271,7 @@ jobs: shell: bash - name: Integration Test env: - PORTER_INTEG_FILE: ../../pkg/porter/lifecycle_integration_test.go + PORTER_INTEG_FILE: lifecycle_integration_test.go run: go run mage.go -v TestIntegration shell: bash pkg_mixin_pkgmgmt_integration_test: @@ -333,4 +333,34 @@ jobs: env: PORTER_INTEG_FILE: ../../pkg/pkgmgmt/client/runner_integration_test.go run: go run mage.go -v TestIntegration + shell: bash + agent_integration_test: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4.1.0 + - uses: actions/setup-go@v4 + with: + go-version: "${{ env.GOVERSION }}" + cache: true + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + - name: Docker Login + uses: docker/login-action@v3.0.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Configure Agent + run: go run mage.go build + shell: bash + - name: Integration Test + env: + PORTER_INTEG_FILE: agent_integration_test.go + run: go run mage.go -v TestIntegration shell: bash \ No newline at end of file diff --git a/.github/workflows/porter-integration-release.yml b/.github/workflows/porter-integration-release.yml index 83e3020c6..cc045f9fe 100644 --- a/.github/workflows/porter-integration-release.yml +++ b/.github/workflows/porter-integration-release.yml @@ -283,7 +283,7 @@ jobs: PORTER_INTEG_FILE: ../../pkg/porter/build_integration_test.go run: go run mage.go -v TestIntegration shell: bash - porter_lifecycle_integration_test: + lifecycle_integration_test: runs-on: ubuntu-latest steps: - name: checkout @@ -310,7 +310,7 @@ jobs: shell: bash - name: Integration Test env: - PORTER_INTEG_FILE: ../../pkg/porter/lifecycle_integration_test.go + PORTER_INTEG_FILE: lifecycle_integration_test.go run: go run mage.go -v TestIntegration shell: bash pkg_mixin_pkgmgmt_integration_test: @@ -372,4 +372,34 @@ jobs: env: PORTER_INTEG_FILE: ../../pkg/pkgmgmt/client/runner_integration_test.go run: go run mage.go -v TestIntegration + shell: bash + agent_integration_test: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v4.1.0 + - uses: actions/setup-go@v4 + with: + go-version: "${{ env.GOVERSION }}" + cache: true + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + - name: Docker Login + uses: docker/login-action@v3.0.0 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Configure Agent + run: go run mage.go build + shell: bash + - name: Integration Test + env: + PORTER_INTEG_FILE: agent_integration_test.go + run: go run mage.go -v TestIntegration shell: bash \ No newline at end of file diff --git a/pkg/agent/agent.go b/pkg/agent/agent.go index 0dd9fe179..66637fac8 100644 --- a/pkg/agent/agent.go +++ b/pkg/agent/agent.go @@ -14,8 +14,8 @@ import ( // allow the tests to capture output var ( - stdout io.Writer = os.Stdout - stderr io.Writer = os.Stderr + Stdout io.Writer = os.Stdout + Stderr io.Writer = os.Stderr ) // The porter agent wraps the porter cli, @@ -67,19 +67,19 @@ func Execute(porterCommand []string, porterHome string, porterConfig string) (er } // Remind everyone the version of Porter we are using - fmt.Fprintf(stderr, "porter version\n") + fmt.Fprintf(Stderr, "porter version\n") cmd := exec.Command(porter, "version") - cmd.Stdout = stderr // send all non-bundle output to stderr - cmd.Stderr = stderr + cmd.Stdout = Stderr // send all non-bundle output to stderr + cmd.Stderr = Stderr if err = cmd.Run(); err != nil { return fmt.Errorf("porter version check failed: %w", err), false } // Run the specified porter command - fmt.Fprintf(stderr, "porter %s\n", strings.Join(porterCommand, " ")) + fmt.Fprintf(Stderr, "porter %s\n", strings.Join(porterCommand, " ")) cmd = exec.Command(porter, porterCommand...) - cmd.Stdout = stdout - cmd.Stderr = stderr + cmd.Stdout = Stdout + cmd.Stderr = Stderr cmd.Stdin = os.Stdin if err := cmd.Start(); err != nil { return err, false @@ -89,7 +89,7 @@ func Execute(porterCommand []string, porterHome string, porterConfig string) (er func copyConfig(relPath string, configFile string, fi os.FileInfo, porterHome string) error { destFile := filepath.Join(porterHome, relPath) - fmt.Fprintln(stderr, "Loading configuration", relPath, "into", destFile) + fmt.Fprintln(Stderr, "Loading configuration", relPath, "into", destFile) src, err := os.OpenFile(configFile, os.O_RDONLY, 0) if err != nil { return err diff --git a/pkg/agent/agent_integration_test.go b/tests/integration/agent_integration_test.go similarity index 89% rename from pkg/agent/agent_integration_test.go rename to tests/integration/agent_integration_test.go index ec7b7f169..e566aa0b3 100644 --- a/pkg/agent/agent_integration_test.go +++ b/tests/integration/agent_integration_test.go @@ -1,6 +1,6 @@ //go:build integration -package agent +package integration import ( "bytes" @@ -9,6 +9,7 @@ import ( "runtime" "testing" + "get.porter.sh/porter/pkg/agent" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/uwu-tools/magex/shx" @@ -21,10 +22,10 @@ func TestExecute(t *testing.T) { stdoutBuff := &bytes.Buffer{} stderrBuff := &bytes.Buffer{} - stdout = stdoutBuff - stderr = stderrBuff + agent.Stdout = stdoutBuff + agent.Stderr = stderrBuff - err, run := Execute([]string{"help"}, home, cfg) + err, run := agent.Execute([]string{"help"}, home, cfg) require.NoError(t, err) assert.True(t, run, "porter should have run") gotStderr := stderrBuff.String() diff --git a/pkg/porter/lifecycle_integration_test.go b/tests/integration/lifecycle_integration_test.go similarity index 82% rename from pkg/porter/lifecycle_integration_test.go rename to tests/integration/lifecycle_integration_test.go index 074f92201..5d8d91dd8 100644 --- a/pkg/porter/lifecycle_integration_test.go +++ b/tests/integration/lifecycle_integration_test.go @@ -1,6 +1,6 @@ //go:build integration -package porter +package integration import ( "context" @@ -8,6 +8,7 @@ import ( "testing" "get.porter.sh/porter/pkg/cnab" + "get.porter.sh/porter/pkg/porter" "get.porter.sh/porter/pkg/storage" "github.com/cnabio/cnab-go/bundle" "github.com/cnabio/cnab-go/bundle/definition" @@ -15,6 +16,7 @@ import ( ) var ( + kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest") kahnlatestHash = "fd4bbe38665531d10bb653140842a370" ) @@ -23,14 +25,14 @@ func TestResolveBundleReference(t *testing.T) { t.Run("current bundle source", func(t *testing.T) { t.Parallel() - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() p.AddTestBundleDir(filepath.Join(p.RepoRoot, "tests/testdata/mybuns"), true) - opts := &BundleReferenceOptions{} + opts := &porter.BundleReferenceOptions{} require.NoError(t, opts.Validate(context.Background(), nil, p.Porter)) - ref, err := p.resolveBundleReference(context.Background(), opts) + ref, err := opts.GetBundleReference(context.Background(), p.Porter) require.NoError(t, err) require.NotEmpty(t, opts.Name) require.NotEmpty(t, ref.Definition) @@ -39,15 +41,15 @@ func TestResolveBundleReference(t *testing.T) { t.Run("cnab file", func(t *testing.T) { t.Parallel() - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() p.AddTestFile(filepath.Join(p.RepoRoot, "build/testdata/bundles/mysql/.cnab/bundle.json"), "bundle.json") - opts := &BundleReferenceOptions{} + opts := &porter.BundleReferenceOptions{} opts.CNABFile = "bundle.json" require.NoError(t, opts.Validate(context.Background(), nil, p.Porter)) - ref, err := p.resolveBundleReference(context.Background(), opts) + ref, err := opts.GetBundleReference(context.Background(), p.Porter) require.NoError(t, err) require.NotEmpty(t, opts.Name) require.NotEmpty(t, ref.Definition) @@ -56,14 +58,14 @@ func TestResolveBundleReference(t *testing.T) { t.Run("reference", func(t *testing.T) { t.Parallel() - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() ctx := p.SetupIntegrationTest() - opts := &BundleReferenceOptions{} + opts := &porter.BundleReferenceOptions{} opts.Reference = "ghcr.io/getporter/examples/porter-hello:v0.2.0" require.NoError(t, opts.Validate(ctx, nil, p.Porter)) - ref, err := p.resolveBundleReference(ctx, opts) + ref, err := opts.GetBundleReference(context.Background(), p.Porter) require.NoError(t, err) require.NotEmpty(t, opts.Name) require.NotEmpty(t, ref.Definition) @@ -74,7 +76,7 @@ func TestResolveBundleReference(t *testing.T) { t.Run("installation name", func(t *testing.T) { t.Parallel() - p := NewTestPorter(t) + p := porter.NewTestPorter(t) defer p.Close() bun := buildExampleBundle() @@ -84,11 +86,11 @@ func TestResolveBundleReference(t *testing.T) { r.Bundle = bun.Bundle r.BundleDigest = kahnlatestHash }) - opts := &BundleReferenceOptions{} + opts := &porter.BundleReferenceOptions{} opts.Name = "example" opts.Namespace = "dev" require.NoError(t, opts.Validate(context.Background(), nil, p.Porter)) - ref, err := p.resolveBundleReference(context.Background(), opts) + ref, err := opts.GetBundleReference(context.Background(), p.Porter) require.NoError(t, err) require.NotEmpty(t, opts.Name) require.NotEmpty(t, ref.Definition)