Skip to content

Commit

Permalink
Remove changes from validate branch
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvam committed May 12, 2019
1 parent 114cea0 commit 015fed6
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 124 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ test-coverage:
$(foreach pkg, $(ALL_PACKAGES),\
go test -coverprofile=coverage.out -covermode=count $(pkg);\
tail -n +2 coverage.out >> coverage-all.out;)
@go tool cover -html=coverage-all.out -o coverage.html
@go tool cover -html=coverage-all.out -o coverage.html
18 changes: 0 additions & 18 deletions cmd/validate.go

This file was deleted.

25 changes: 0 additions & 25 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,6 @@ type Configs struct {
Tasks map[string][]Task
}

// Validate config and return a list of errors and warnings. If errors are not critical/only warnings, it returns param `ok` as true, else false
func (configs *Configs) Validate() ([]error, bool) {
var errs []error
var warnings []error
if len(configs.Tasks) == 0 {
warnings = append(warnings, fmt.Errorf("dunner: No tasks defined"))
}

for taskName, tasks := range configs.Tasks {
for _, task := range tasks {
if task.Image == "" {
errs = append(errs, fmt.Errorf(`dunner: [%s] Image repository name cannot be empty`, taskName))
}
if len(task.Command) == 0 {
errs = append(errs, fmt.Errorf("dunner: [%s] Commands not defined for task with image %s", taskName, task.Image))
}
}
}
if len(errs) > 0 {
errs = append(errs, warnings...)
return errs, false
}
return warnings, true
}

// GetConfigs reads and parses tasks from the dunner file
func GetConfigs(filename string) (*Configs, error) {
fileContents, err := ioutil.ReadFile(filename)
Expand Down
47 changes: 0 additions & 47 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,50 +54,3 @@ test:
}

}

func TestConfigs_Validate(t *testing.T) {
tasks := make(map[string][]Task, 0)
tasks["stats"] = []Task{getSampleTask()}
configs := &Configs{Tasks: tasks}

errs, ok := configs.Validate()

if !ok || len(errs) != 0 {
t.Fatalf("Configs Validation failed, expected to pass")
}
}

func TestConfigs_ValidateWithNoTasks(t *testing.T) {
tasks := make(map[string][]Task, 0)
configs := &Configs{Tasks: tasks}

errs, ok := configs.Validate()

if !ok || len(errs) != 1 {
t.Fatalf("Configs validation failed")
}
if errs[0].Error() != "dunner: No tasks defined" {
t.Fatalf("Configs Validation error message not as expected")
}
}

func TestConfigs_ValidateWithParseErrors(t *testing.T) {
tasks := make(map[string][]Task, 0)
task := Task{Image: "", Command: []string{}}
tasks["stats"] = []Task{task}
configs := &Configs{Tasks: tasks}

errs, ok := configs.Validate()

if ok || len(errs) != 2 {
t.Fatalf("Configs validation failed")
}

if errs[0].Error() != "dunner: [stats] Image repository name cannot be empty" || errs[1].Error() != "dunner: [stats] Commands not defined for task with image " {
t.Fatalf("Configs Validation error message not as expected")
}
}

func getSampleTask() Task {
return Task{Image: "image_name", Command: []string{"node", "--version"}}
}
26 changes: 0 additions & 26 deletions pkg/config/validate.go

This file was deleted.

11 changes: 4 additions & 7 deletions pkg/dunner/dunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ func Do(_ *cobra.Command, args []string) {
if err != nil {
log.Fatal(err)
}
errs, ok := configs.Validate()
for _, err := range errs {
log.Error(err)
}
if !ok {
os.Exit(1)
}

execTask(configs, args[0], args[1:])
}
Expand Down Expand Up @@ -98,6 +91,10 @@ func process(configs *config.Configs, s *docker.Step, wg *sync.WaitGroup, args [
log.Fatal(err)
}

if s.Image == "" {
log.Fatalf(`dunner: image repository name cannot be empty`)
}

pout, err := (*s).Exec()
if err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 015fed6

Please sign in to comment.