From 4f1f1af8b464dd01b8828ce8448898d93f012949 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Fri, 23 Aug 2019 22:34:50 +0530 Subject: [PATCH 1/2] add error handling for bad directory --- generators/static.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/generators/static.go b/generators/static.go index b91f1ac..fd929d9 100644 --- a/generators/static.go +++ b/generators/static.go @@ -19,6 +19,10 @@ func (sg *StaticGenerator) Generate(component *core.Component) (manifest string, staticPath := path.Join(component.PhysicalPath, component.Path) staticFiles, err := ioutil.ReadDir(staticPath) + if err != nil { + log.Errorf("error reading from directory %s", staticPath); + return "", err + } manifests := "" for _, staticFile := range staticFiles { From 15abcf99f130b14722a75795c31adc7ebaf65db2 Mon Sep 17 00:00:00 2001 From: Shubham Sharma Date: Sat, 24 Aug 2019 01:00:41 +0530 Subject: [PATCH 2/2] test new behavior --- generators/static_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 generators/static_test.go diff --git a/generators/static_test.go b/generators/static_test.go new file mode 100644 index 0000000..43e5c4a --- /dev/null +++ b/generators/static_test.go @@ -0,0 +1,20 @@ +package generators + +import ( + "github.com/microsoft/fabrikate/core" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestStaticGenerator_Generate(t *testing.T) { + component := core.Component{ + Name: "foo", + Path: "", + PhysicalPath: "../testdata/invaliddir", + } + + generator := &StaticGenerator{} + _, err := generator.Generate(&component) + assert.NotNil(t, err) +}