Skip to content

Commit

Permalink
Merge branch 'main' into linterNoMixins
Browse files Browse the repository at this point in the history
  • Loading branch information
schristoff authored Feb 15, 2024
2 parents 29b28a9 + f2506a2 commit b0511c8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
1 change: 0 additions & 1 deletion .github/workflows/integ-reuseable-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
required: true
registry:
type: string
required: true
default: ghcr.io
env:
GOVERSION: 1.20.7
Expand Down
2 changes: 2 additions & 0 deletions cmd/porter/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"testing"

"get.porter.sh/porter/pkg"
"get.porter.sh/porter/tests"

"get.porter.sh/porter/pkg/porter"
Expand Down Expand Up @@ -189,6 +190,7 @@ func TestBuildValidate_Driver(t *testing.T) {
// noop
return nil
}
p.FileSystem.WriteFile("porter.yaml", []byte(""), pkg.FileModeWritable)

err := rootCmd.Execute()
if tc.wantError == "" {
Expand Down
11 changes: 10 additions & 1 deletion pkg/porter/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,16 @@ func (o *BuildOptions) Validate(p *Porter) error {
return err
}

return o.BundleDefinitionOptions.Validate(p.Context)
err = o.BundleDefinitionOptions.Validate(p.Context)
if err != nil {
return err
}

if o.File == "" {
return fmt.Errorf("could not find porter.yaml in the current directory %s, make sure you are in the right directory or specify the porter manifest with --file", o.Dir)
}

return nil
}

func stringSliceContains(allowedValues []string, value string) bool {
Expand Down
27 changes: 27 additions & 0 deletions pkg/porter/build_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package porter

import (
"fmt"
"testing"

"get.porter.sh/porter/pkg"
"get.porter.sh/porter/pkg/manifest"
"get.porter.sh/porter/pkg/mixin"
"get.porter.sh/porter/pkg/pkgmgmt"
Expand Down Expand Up @@ -36,3 +38,28 @@ func TestPorter_GetUsedMixins(t *testing.T) {
assert.Len(t, results, 1)
assert.Equal(t, 1, testMixins.GetCalled("exec"), "expected the exec mixin to be called once")
}

func TestPorter_ErrorMessageOnMissingPorterYaml(t *testing.T) {
p := NewTestPorter(t)
defer p.Close()

o := BuildOptions{
BundleDefinitionOptions: BundleDefinitionOptions{},
}

err := o.Validate(p.Porter)
require.ErrorContains(t, err, fmt.Sprintf("could not find porter.yaml in the current directory %s, make sure you are in the right directory or specify the porter manifest with --file", o.Dir))
}

func TestPorter_NoErrorWhenPorterYamlIsPresent(t *testing.T) {
p := NewTestPorter(t)
defer p.Close()

o := BuildOptions{
BundleDefinitionOptions: BundleDefinitionOptions{},
}
p.FileSystem.WriteFile("porter.yaml", []byte(""), pkg.FileModeWritable)

err := o.Validate(p.Porter)
require.NoError(t, err, "validate BuildOptions failed")
}

0 comments on commit b0511c8

Please sign in to comment.