Skip to content

Commit

Permalink
WIP: Move some into test/integration folder
Browse files Browse the repository at this point in the history
Signed-off-by: David Gannon <19214156+dgannon991@users.noreply.github.com>
  • Loading branch information
dgannon991 committed Dec 31, 2024
1 parent b34501b commit da55207
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 30 deletions.
34 changes: 32 additions & 2 deletions .github/workflows/porter-integration-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
34 changes: 32 additions & 2 deletions .github/workflows/porter-integration-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
18 changes: 9 additions & 9 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build integration

package agent
package integration

import (
"bytes"
Expand All @@ -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"
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
//go:build integration

package porter
package integration

import (
"context"
"path/filepath"
"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"
"github.com/stretchr/testify/require"
)

var (
kahnlatest = cnab.MustParseOCIReference("deislabs/kubekahn:latest")
kahnlatestHash = "fd4bbe38665531d10bb653140842a370"
)

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit da55207

Please sign in to comment.