From 4bc183a8a15367fa30bf7a6e6780297ba4afe529 Mon Sep 17 00:00:00 2001 From: Adam Wasila Date: Sun, 14 Jun 2020 11:02:25 +0200 Subject: [PATCH] Add basic unit tests for label attribute --- task_test.go | 84 ++++++++++++++++++++++++++++ testdata/label_list/Taskfile.yml | 6 ++ testdata/label_status/Taskfile.yml | 7 +++ testdata/label_summary/Taskfile.yml | 8 +++ testdata/label_uptodate/Taskfile.yml | 7 +++ testdata/label_var/Taskfile.yml | 10 ++++ 6 files changed, 122 insertions(+) create mode 100644 testdata/label_list/Taskfile.yml create mode 100644 testdata/label_status/Taskfile.yml create mode 100644 testdata/label_summary/Taskfile.yml create mode 100644 testdata/label_uptodate/Taskfile.yml create mode 100644 testdata/label_var/Taskfile.yml diff --git a/task_test.go b/task_test.go index 03185bcb..e8bbe438 100644 --- a/task_test.go +++ b/task_test.go @@ -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" diff --git a/testdata/label_list/Taskfile.yml b/testdata/label_list/Taskfile.yml new file mode 100644 index 00000000..5c7db94b --- /dev/null +++ b/testdata/label_list/Taskfile.yml @@ -0,0 +1,6 @@ +version: '3' + +tasks: + foo: + label: "foobar" + desc: "task description" diff --git a/testdata/label_status/Taskfile.yml b/testdata/label_status/Taskfile.yml new file mode 100644 index 00000000..79747464 --- /dev/null +++ b/testdata/label_status/Taskfile.yml @@ -0,0 +1,7 @@ +version: '3' + +tasks: + foo: + label: "foobar" + status: + - "false" \ No newline at end of file diff --git a/testdata/label_summary/Taskfile.yml b/testdata/label_summary/Taskfile.yml new file mode 100644 index 00000000..c649c09f --- /dev/null +++ b/testdata/label_summary/Taskfile.yml @@ -0,0 +1,8 @@ +version: '3' + +tasks: + foo: + label: "foobar" + desc: description + status: + - echo "I'm ok" \ No newline at end of file diff --git a/testdata/label_uptodate/Taskfile.yml b/testdata/label_uptodate/Taskfile.yml new file mode 100644 index 00000000..2219f4a6 --- /dev/null +++ b/testdata/label_uptodate/Taskfile.yml @@ -0,0 +1,7 @@ +version: '3' + +tasks: + foo: + label: "foobar" + status: + - echo "I'm ok" \ No newline at end of file diff --git a/testdata/label_var/Taskfile.yml b/testdata/label_var/Taskfile.yml new file mode 100644 index 00000000..b47a76ac --- /dev/null +++ b/testdata/label_var/Taskfile.yml @@ -0,0 +1,10 @@ +version: '3' + +vars: + BAR: baz + +tasks: + foo: + label: "foo{{.BAR}}" + status: + - echo "I'm ok" \ No newline at end of file