Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build missing yaml message #2995

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ and we will add you. **All** contributors belong here. 💯
- [Xin Fu](https://github.com/imfing)
- [KallyDev](https://github.com/kallydev)
- [Salman Shah](https://github.com/sbshah97)
- [Ray Terrill](https://github.com/rayterrill)
- [Ray Terrill](https://github.com/rayterrill)
- [Kim Christensen](https://github.com/kichristensen)
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")
}
Loading