-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor_test.go
More file actions
78 lines (64 loc) · 1.69 KB
/
Copy pathexecutor_test.go
File metadata and controls
78 lines (64 loc) · 1.69 KB
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
//go:build integration
package taskrunner
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
var (
sampleTestDir = "sample_tests"
tmpDir = "temp"
tmpDir2 = "temp2"
)
var tr = GetTaskRunner()
func TestMain(m *testing.M) {
tr.Remove(tmpDir, tmpDir2)
exitCode := m.Run()
os.Exit(exitCode)
}
func TestCommandSuccessful(t *testing.T) {
tr.ExecuteInDir(sampleTestDir, "go test success_test.go")
}
func TestDirCreationAndDeletion(t *testing.T) {
assert.False(t, checkIfExists(tmpDir))
defer tr.Remove(tmpDir)
tr.MakeDir(tmpDir)
assert.True(t, checkIfExists(tmpDir))
createFile(t, tmpDir+"/test.txt")
assert.True(t, checkIfExists(tmpDir+"/test.txt"))
tr.Remove(tmpDir)
assert.False(t, checkIfExists(tmpDir))
}
func checkIfExists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
tr.Log.Error("error checking if file exists: %v", err)
return false
}
func TestDaemon(t *testing.T) {
assert.Equal(t, 0, len(tr.Config.idsOfDaemonProcessesCreated))
tr.StartDaemon(".", "sleep 100")
assert.Equal(t, 1, len(tr.Config.idsOfDaemonProcessesCreated))
processId := tr.Config.idsOfDaemonProcessesCreated[0]
command := fmt.Sprintf("bash -c 'ps -p %d -o cmd= | grep -q sleep'", processId)
tr.ExecuteInDir(".", command)
tr.Cleanup()
assert.Equal(t, 0, len(tr.Config.idsOfDaemonProcessesCreated))
command = fmt.Sprintf("bash -c '! ps -p %d'", processId)
tr.ExecuteInDir(".", command)
}
func TestCustomCleanupFunction(t *testing.T) {
defer tr.Remove(tmpDir)
tr.Config.CleanupFunc = func() {
tr.MakeDir(tmpDir)
}
assert.False(t, checkIfExists(tmpDir))
tr.Cleanup()
assert.True(t, checkIfExists(tmpDir))
}