Skip to content

Commit

Permalink
WIP: Moved all tests to integration
Browse files Browse the repository at this point in the history
Signed-off-by: David Gannon <[email protected]>
  • Loading branch information
dgannon991 committed Jan 1, 2025
1 parent da55207 commit 843827b
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 66 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/porter-integration-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/porter-integration-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pkg/porter/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

type BuildOptions struct {
BundleDefinitionOptions
metadataOpts
MetadataOpts
build.BuildImageOptions

// NoLint indicates if lint should be run before build.
Expand Down
4 changes: 2 additions & 2 deletions pkg/porter/generateManifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/porter/generateManifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build integration

package porter
package integration

import (
"context"
Expand All @@ -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"
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 == "" {
Expand All @@ -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)
Expand All @@ -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)

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

Expand All @@ -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)
Expand All @@ -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`,
}}

Expand All @@ -259,36 +259,31 @@ 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)
})
}

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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//go:build integration

package mixin
package integration

import (
"context"
"os"
"testing"

"get.porter.sh/porter/pkg/config"
"get.porter.sh/porter/pkg/mixin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -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)
}
Loading

0 comments on commit 843827b

Please sign in to comment.