Skip to content

Commit b0511c8

Browse files
authored
Merge branch 'main' into linterNoMixins
2 parents 29b28a9 + f2506a2 commit b0511c8

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

.github/workflows/integ-reuseable-workflow.yml

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
required: true
99
registry:
1010
type: string
11-
required: true
1211
default: ghcr.io
1312
env:
1413
GOVERSION: 1.20.7

cmd/porter/bundle_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
"testing"
88

9+
"get.porter.sh/porter/pkg"
910
"get.porter.sh/porter/tests"
1011

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

193195
err := rootCmd.Execute()
194196
if tc.wantError == "" {

pkg/porter/build.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,16 @@ func (o *BuildOptions) Validate(p *Porter) error {
7272
return err
7373
}
7474

75-
return o.BundleDefinitionOptions.Validate(p.Context)
75+
err = o.BundleDefinitionOptions.Validate(p.Context)
76+
if err != nil {
77+
return err
78+
}
79+
80+
if o.File == "" {
81+
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)
82+
}
83+
84+
return nil
7685
}
7786

7887
func stringSliceContains(allowedValues []string, value string) bool {

pkg/porter/build_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package porter
22

33
import (
4+
"fmt"
45
"testing"
56

7+
"get.porter.sh/porter/pkg"
68
"get.porter.sh/porter/pkg/manifest"
79
"get.porter.sh/porter/pkg/mixin"
810
"get.porter.sh/porter/pkg/pkgmgmt"
@@ -36,3 +38,28 @@ func TestPorter_GetUsedMixins(t *testing.T) {
3638
assert.Len(t, results, 1)
3739
assert.Equal(t, 1, testMixins.GetCalled("exec"), "expected the exec mixin to be called once")
3840
}
41+
42+
func TestPorter_ErrorMessageOnMissingPorterYaml(t *testing.T) {
43+
p := NewTestPorter(t)
44+
defer p.Close()
45+
46+
o := BuildOptions{
47+
BundleDefinitionOptions: BundleDefinitionOptions{},
48+
}
49+
50+
err := o.Validate(p.Porter)
51+
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))
52+
}
53+
54+
func TestPorter_NoErrorWhenPorterYamlIsPresent(t *testing.T) {
55+
p := NewTestPorter(t)
56+
defer p.Close()
57+
58+
o := BuildOptions{
59+
BundleDefinitionOptions: BundleDefinitionOptions{},
60+
}
61+
p.FileSystem.WriteFile("porter.yaml", []byte(""), pkg.FileModeWritable)
62+
63+
err := o.Validate(p.Porter)
64+
require.NoError(t, err, "validate BuildOptions failed")
65+
}

0 commit comments

Comments
 (0)