Skip to content

Commit

Permalink
Add basic unit tests for label attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwasila committed Jun 14, 2020
1 parent 9f83311 commit 4bc183a
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
84 changes: 84 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,90 @@ func TestStatusChecksum(t *testing.T) {
assert.Equal(t, `task: Task "build" is up to date`+"\n", buff.String())
}

func TestLabelUpToDate(t *testing.T) {
const dir = "testdata/label_uptodate"

var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
assert.Contains(t, buff.String(), "foobar")
}

func TestLabelSummary(t *testing.T) {
const dir = "testdata/label_summary"

var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Summary: true,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
assert.Contains(t, buff.String(), "foobar")
}

func TestLabelInStatus(t *testing.T) {
const dir = "testdata/label_status"

e := task.Executor{
Dir: dir,
}
assert.NoError(t, e.Setup())
err := e.Status(context.Background(), taskfile.Call{Task: "foo"})
if assert.Error(t, err) {
assert.Contains(t, err.Error(), "foobar")
}
}

func TestLabelWithVariableExpansion(t *testing.T) {
const dir = "testdata/label_var"

var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
assert.Contains(t, buff.String(), "foobaz")
}

func TestLabelInSummary(t *testing.T) {
const dir = "testdata/label_summary"

var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "foo"}))
assert.Contains(t, buff.String(), "foobar")
}

func TestLabelInList(t *testing.T) {
const dir = "testdata/label_list"

var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
e.PrintTasksHelp()
assert.Contains(t, buff.String(), "foobar")
}

func TestStatusVariables(t *testing.T) {
const dir = "testdata/status_vars"

Expand Down
6 changes: 6 additions & 0 deletions testdata/label_list/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'

tasks:
foo:
label: "foobar"
desc: "task description"
7 changes: 7 additions & 0 deletions testdata/label_status/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'

tasks:
foo:
label: "foobar"
status:
- "false"
8 changes: 8 additions & 0 deletions testdata/label_summary/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'

tasks:
foo:
label: "foobar"
desc: description
status:
- echo "I'm ok"
7 changes: 7 additions & 0 deletions testdata/label_uptodate/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3'

tasks:
foo:
label: "foobar"
status:
- echo "I'm ok"
10 changes: 10 additions & 0 deletions testdata/label_var/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

vars:
BAR: baz

tasks:
foo:
label: "foo{{.BAR}}"
status:
- echo "I'm ok"

0 comments on commit 4bc183a

Please sign in to comment.