Skip to content

Commit

Permalink
[+] make built-in 100% tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
pashagolub committed May 10, 2020
1 parent febeb1f commit 5778939
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/tasks/tasks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tasks

import (
"errors"
"fmt"
"strconv"
"time"
Expand All @@ -22,8 +23,12 @@ func ExecuteTask(name string, paramValues []string) error {
if len(paramValues) == 0 {
paramValues = append(paramValues, "")
}
f := Tasks[name]
if f == nil {
return errors.New("No built-in task found: " + name)
}
for _, val := range paramValues {
err := Tasks[name](val)
err := f(val)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,19 @@ func TestDownloadFile(t *testing.T) {
assert.NoError(t, taskDownloadFile(`{"workersnum": 0, "fileurls": ["http://foo.bar"], "destpath": "." }`),
"Downlod with correct json input should succeed")
}

func TestNoOp(t *testing.T) {
assert.NoError(t, taskNoOp("foo"))
}

func TestTaskSleep(t *testing.T) {
assert.NoError(t, taskSleep("1"))
assert.Error(t, taskSleep("foo"))
}

func TestExecuteTask(t *testing.T) {
assert.Error(t, ExecuteTask("foo", []string{}))
assert.Error(t, ExecuteTask("Sleep", []string{"foo"}))
assert.NoError(t, ExecuteTask("NoOp", []string{}))
assert.NoError(t, ExecuteTask("NoOp", []string{"foo", "bar"}))
}

0 comments on commit 5778939

Please sign in to comment.