Skip to content

Commit

Permalink
fix(check): print error about failing files now
Browse files Browse the repository at this point in the history
Signed-off-by: Felipe Zipitria <[email protected]>
  • Loading branch information
fzipi committed Mar 22, 2021
1 parent 5b20d99 commit 99f3e8a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
14 changes: 11 additions & 3 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cmd

import (
"fmt"
"os"

"github.com/fzipi/go-ftw/test"
"github.com/rs/zerolog/log"

"github.com/kyokomi/emoji"
"github.com/spf13/cobra"
Expand All @@ -26,10 +28,16 @@ func init() {
}

func checkFiles(dir string) {
files := fmt.Sprintf("%s/**/*.y[a]ml", dir)
var exit int
files := fmt.Sprintf("%s/**/*.yaml", dir)
log.Debug().Msgf("ftw/check: checking files using glob pattern: %s", files)
tests, err := test.GetTestsFromFiles(files)
if err != nil {
emoji.Printf("ftw: :red_cross: oops, found %s\n", err.Error())
emoji.Printf("ftw/check: :collision: oops, found %s\n", err.Error())
exit = 1
} else {
emoji.Printf("ftw/check: checked %d files, everything looks good!\n", len(tests))
exit = 0
}
emoji.Printf("ftw: checked %d files, everything looks good!\n", len(tests))
os.Exit(exit)
}
15 changes: 10 additions & 5 deletions test/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@ func GetTestsFromFiles(globPattern string) ([]FTWTest, error) {
var tests []FTWTest
var err error

testFiles, _ := filepath.Glob(globPattern)
testFiles, err := filepath.Glob(globPattern)

if err != nil {
log.Info().Msgf("ftw/test: error getting test files from %s", globPattern)
return tests, err
}

for _, test := range testFiles {
t, err := readTest(test)
if err != nil {
break
} else {
tests = append(tests, *t)
log.Debug().Msgf("ftw/test: error reading %s file. Is it patched?", test)
return tests, err
}
tests = append(tests, *t)
}

return tests, err
return tests, nil
}

func readTest(filename string) (t *FTWTest, err error) {
Expand Down
2 changes: 1 addition & 1 deletion test/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestGetFromBadYAML(t *testing.T) {
filename, _ := utils.CreateTempFileWithContent(wrongYamlTest, "test-yaml-*")
_, err := GetTestsFromFiles(filename)

if err != nil {
if err == nil {
t.Fatalf("Error!")
}
}

0 comments on commit 99f3e8a

Please sign in to comment.