-
Notifications
You must be signed in to change notification settings - Fork 0
/
integration_test.go
129 lines (100 loc) · 3.18 KB
/
integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//go:build integration
// +build integration
package main
import (
"os"
"os/exec"
"strings"
"testing"
"tuki/internal"
"github.com/stretchr/testify/assert"
)
func must[T any](value T, err error) T {
if err != nil {
panic(err)
}
return value
}
func must0(err error) {
if err != nil {
panic(err)
}
}
func TestMain(t *testing.T) {
// Setup
bareRepoDir, repoDir := setupTestRepo(t, "test/testdata/basic-repo/")
defer os.RemoveAll(bareRepoDir)
defer os.RemoveAll(repoDir)
// Run one tick of tuki
runTuki(t, bareRepoDir)
// Ensure that the state file was committed
cmd := exec.Command("git", "log", "--patch", "-n", "1", "master")
cmd.Dir = bareRepoDir
output := must(cmd.Output())
assert.Contains(t, string(output), "state.json")
// Check that the state file has 2 tasks, one failed (fails.sh) and one completed (hello-world.sh)
cmd = exec.Command("git", "show", "master:.tuki/state.jsonl")
cmd.Dir = bareRepoDir
output = must(cmd.Output())
tasksStore := must(internal.LoadTaskStore(strings.NewReader(string(output))))
task, ok := tasksStore.GetTask("fails.sh")
assert.True(t, ok)
assert.True(t, task.Status == internal.StatusFailed)
task, ok = tasksStore.GetTask("hello-world.sh")
assert.True(t, ok)
assert.True(t, task.Status == internal.StatusCompleted)
}
func TestHarnessFile(t *testing.T) {
// Setup
bareRepoDir, repoDir := setupTestRepo(t, "test/testdata/python-harness-repo/")
defer os.RemoveAll(bareRepoDir)
defer os.RemoveAll(repoDir)
// Run one tick of tuki
runTuki(t, bareRepoDir)
// Ensure that the state file was committed
cmd := exec.Command("git", "log", "--patch", "-n", "1", "master")
cmd.Dir = bareRepoDir
output := must(cmd.Output())
assert.Contains(t, string(output), "state.json")
// Check that the state file has 2 tasks, one failed (fails.sh) and one completed (hello-world.sh)
cmd = exec.Command("git", "show", "master:.tuki/state.jsonl")
cmd.Dir = bareRepoDir
output = must(cmd.Output())
tasksStore := must(internal.LoadTaskStore(strings.NewReader(string(output))))
task, ok := tasksStore.GetTask("fails.py")
assert.True(t, ok)
assert.True(t, task.Status == internal.StatusFailed)
task, ok = tasksStore.GetTask("hello-world.py")
assert.True(t, ok)
assert.True(t, task.Status == internal.StatusCompleted)
}
func setupTestRepo(t *testing.T, repoPath string) (string, string) {
bareRepoDir := must(os.MkdirTemp("", "tuki-testrepo-bare"))
repoDir := must(os.MkdirTemp("", "tuki-testrepo"))
cmd := exec.Command("cp", "-r", repoPath, repoDir)
cmd.Dir = "."
cmd.Stderr = os.Stderr
must0(cmd.Run())
cmd = exec.Command("git", "init")
cmd.Dir = repoDir
must0(cmd.Run())
cmd = exec.Command("git", "add", ".")
cmd.Dir = repoDir
must0(cmd.Run())
cmd = exec.Command("git", "commit", "-m", "Initial commit")
cmd.Dir = repoDir
must0(cmd.Run())
cmd = exec.Command("git", "clone", "--bare", repoDir, bareRepoDir)
must0(cmd.Run())
cmd = exec.Command("git", "remote", "add", "origin", bareRepoDir)
cmd.Dir = repoDir
must0(cmd.Run())
return bareRepoDir, repoDir
}
func runTuki(t *testing.T, bareRepoDir string) {
os.Setenv("REPO_URL", bareRepoDir)
defer os.Unsetenv("REPO_URL")
os.Setenv("MAX_TICKS", "1")
defer os.Unsetenv("MAX_TICKS")
main()
}