diff --git a/internal/pkg/config/manifest.go b/internal/pkg/config/manifest.go index 000aa08..f6cf11e 100644 --- a/internal/pkg/config/manifest.go +++ b/internal/pkg/config/manifest.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "os" "path/filepath" + "strings" "github.com/ghodss/yaml" "github.com/kristofferahl/go-centry/internal/pkg/cmd" @@ -78,6 +79,10 @@ type LogConfig struct { // LoadManifest reads, parses and returns a manifest root object func LoadManifest(manifest string) (*Manifest, error) { + if !strings.HasSuffix(manifest, ".yaml") && !strings.HasSuffix(manifest, ".yml") { + return nil, fmt.Errorf("manifest file must have a valid extension (yaml,yml)") + } + mp, _ := filepath.Abs(manifest) if _, err := os.Stat(mp); os.IsNotExist(err) { diff --git a/internal/pkg/config/manifest_test.go b/internal/pkg/config/manifest_test.go index 4bc3718..7bc3bd0 100644 --- a/internal/pkg/config/manifest_test.go +++ b/internal/pkg/config/manifest_test.go @@ -33,10 +33,17 @@ func TestManifest(t *testing.T) { }) g.It("returns error when path is invalid", func() { - m, err := LoadManifest("foo") + m, err := LoadManifest("foo.yaml") g.Assert(m == nil).IsTrue("exected manifest to be nil") g.Assert(err != nil).IsTrue("expected error") - g.Assert(err.Error()).Equal("manifest file not found (path=foo)") + g.Assert(err.Error()).Equal("manifest file not found (path=foo.yaml)") + }) + + g.It("returns error when path is not a yaml or yml file", func() { + m, err := LoadManifest("foo.bar") + g.Assert(m == nil).IsTrue("exected manifest to be nil") + g.Assert(err != nil).IsTrue("expected error") + g.Assert(err.Error()).Equal("manifest file must have a valid extension (yaml,yml)") }) })