Skip to content

Commit

Permalink
test: add tests for definition checks in the fingerprint tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Nov 16, 2023
1 parent aacf5f0 commit bfe40d2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ tasks:
clean:test:
desc: Cleans test temp files and folders
cmds:
- git clean -fdX -q -d testdata/
- git clean -fdX -q -d testdata/ internal/fingerprint/testdata/

lint:
desc: Runs golangci-lint
Expand Down
52 changes: 49 additions & 3 deletions internal/fingerprint/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package fingerprint

import (
"context"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/go-task/task/v3/internal/filepathext"
"github.com/go-task/task/v3/internal/mocks"
"github.com/go-task/task/v3/taskfile"
)
Expand All @@ -26,6 +28,9 @@ import (
// | false | true | false |
// | false | false | false |
func TestIsTaskUpToDate(t *testing.T) {
tempDir := filepathext.SmartJoin("testdata", ".task")
os.RemoveAll(tempDir)

tests := []struct {
name string
task *taskfile.Task
Expand All @@ -44,7 +49,19 @@ func TestIsTaskUpToDate(t *testing.T) {
expected: false,
},
{
name: "expect TRUE when no status is defined and sources are up-to-date",
name: "expect False when no status is defined and sources are up-to-date for the first time",
task: &taskfile.Task{
Status: nil,
Sources: []string{"sources"},
},
setupMockStatusChecker: nil,
setupMockSourcesChecker: func(m *mocks.SourcesCheckable) {
m.EXPECT().IsUpToDate(mock.Anything).Return(true, nil)
},
expected: false,
},
{
name: "expect False when no status is defined and sources are up-to-date for the second time",
task: &taskfile.Task{
Status: nil,
Sources: []string{"sources"},
Expand All @@ -68,7 +85,19 @@ func TestIsTaskUpToDate(t *testing.T) {
expected: false,
},
{
name: "expect TRUE when status is up-to-date and sources are not defined",
name: "expect False when status is up-to-date and sources are not defined for the first time",
task: &taskfile.Task{
Status: []string{"status"},
Sources: nil,
},
setupMockStatusChecker: func(m *mocks.StatusCheckable) {
m.EXPECT().IsUpToDate(mock.Anything, mock.Anything).Return(true, nil)
},
setupMockSourcesChecker: nil,
expected: false,
},
{
name: "expect TRUE when status is up-to-date and sources are not defined for the second time",
task: &taskfile.Task{
Status: []string{"status"},
Sources: nil,
Expand All @@ -80,7 +109,21 @@ func TestIsTaskUpToDate(t *testing.T) {
expected: true,
},
{
name: "expect TRUE when status and sources are up-to-date",
name: "expect False when status and sources are up-to-date for the first time",
task: &taskfile.Task{
Status: []string{"status"},
Sources: []string{"sources"},
},
setupMockStatusChecker: func(m *mocks.StatusCheckable) {
m.EXPECT().IsUpToDate(mock.Anything, mock.Anything).Return(true, nil)
},
setupMockSourcesChecker: func(m *mocks.SourcesCheckable) {
m.EXPECT().IsUpToDate(mock.Anything).Return(true, nil)
},
expected: false,
},
{
name: "expect True when status and sources are up-to-date for the second time",
task: &taskfile.Task{
Status: []string{"status"},
Sources: []string{"sources"},
Expand Down Expand Up @@ -165,6 +208,9 @@ func TestIsTaskUpToDate(t *testing.T) {
tt.task,
WithStatusChecker(mockStatusChecker),
WithSourcesChecker(mockSourcesChecker),
func(config *CheckerConfig) {
config.tempDir = tempDir
},
)
require.NoError(t, err)
assert.Equal(t, tt.expected, result)
Expand Down
1 change: 1 addition & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ func TestLabelInStatus(t *testing.T) {

func TestLabelWithVariableExpansion(t *testing.T) {
const dir = "testdata/label_var"
os.RemoveAll(filepathext.SmartJoin(dir, ".task"))

var buff bytes.Buffer
e := task.Executor{
Expand Down

0 comments on commit bfe40d2

Please sign in to comment.