Skip to content

Commit

Permalink
feat: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
pd93 committed Jun 28, 2024
1 parent 9213f5e commit 398e3dd
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
18 changes: 18 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,24 @@ func TestRunOnlyRunsJobsHashOnce(t *testing.T) {
tt.Run(t)
}

func TestRunOnceSharedDeps(t *testing.T) {
const dir = "testdata/run_once_shared_deps"

var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
ForceAll: true,
}
require.NoError(t, e.Setup())
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "build"}))

assert.Regexp(t, regexp.MustCompile(`task: \[service-[a,b]:library:build\] echo "build library"`), buff.String())
assert.Contains(t, buff.String(), `task: [service-a:build] echo "build a"`)
assert.Contains(t, buff.String(), `task: [service-b:build] echo "build b"`)
}

func TestDeferredCmds(t *testing.T) {
const dir = "testdata/deferred"
var buff bytes.Buffer
Expand Down
11 changes: 11 additions & 0 deletions testdata/run_once_shared_deps/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'

includes:
service-a: ./service-a
service-b: ./service-b

tasks:
build:
deps:
- service-a:build
- service-b:build
9 changes: 9 additions & 0 deletions testdata/run_once_shared_deps/library/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3'

tasks:
build:
run: once
cmds:
- echo "build library"
sources:
- src/**/*
15 changes: 15 additions & 0 deletions testdata/run_once_shared_deps/service-a/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'

includes:
library:
taskfile: ../library/Taskfile.yml
dir: ../library

tasks:
build:
run: once
deps: [library:build]
cmds:
- echo "build a"
sources:
- src/**/*
1 change: 1 addition & 0 deletions testdata/run_once_shared_deps/service-a/src/imasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main
15 changes: 15 additions & 0 deletions testdata/run_once_shared_deps/service-b/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'

includes:
library:
taskfile: ../library/Taskfile.yml
dir: ../library

tasks:
build:
run: once
deps: [library:build]
cmds:
- echo "build b"
sources:
- src/**/*
1 change: 1 addition & 0 deletions testdata/run_once_shared_deps/service-b/src/imasource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package main

0 comments on commit 398e3dd

Please sign in to comment.