-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworker_test.go
More file actions
97 lines (73 loc) · 1.81 KB
/
worker_test.go
File metadata and controls
97 lines (73 loc) · 1.81 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"os"
"path/filepath"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"distbuild/boong/worker/proto"
)
const (
testWorkerDir = "test-worker"
testWorkerFile = "test_worker.c"
testWorkerData = "int main() {return 0;}"
)
func initWorkerTest() server {
return server{}
}
func TestValidateBuildFile(t *testing.T) {
s := initWorkerTest()
workSpacePath, _ = os.MkdirTemp("", testWorkerDir)
defer func(path string) {
_ = os.RemoveAll(path)
}(workSpacePath)
base := "/remote"
hash := sha256.New()
r := strings.NewReader(testWorkerData)
_, _ = io.Copy(hash, r)
buildFiles := []*proto.BuildFile{
{
FilePath: filepath.Join(base, testWorkerFile),
FileData: []byte(testWorkerData),
CheckSum: hex.EncodeToString(hash.Sum(nil)),
},
}
err := s.validateBuildFile(buildFiles)
assert.Equal(t, nil, err)
}
func TestSetBuildPath(t *testing.T) {
s := initWorkerTest()
workSpacePath = os.TempDir()
base := "/path"
targets := []string{
filepath.Join(base, testWorkerDir),
}
defer func(path string) {
_ = os.RemoveAll(path)
}(targets[0])
err := s.setBuildPath(targets)
assert.Equal(t, nil, err)
}
func TestRunBuild(t *testing.T) {
s := initWorkerTest()
workSpacePath = os.TempDir()
_ = os.WriteFile(filepath.Join(workSpacePath, testWorkerFile), []byte(testWorkerData), 0644)
defer func(path string) {
_ = os.RemoveAll(path)
}(filepath.Join(workSpacePath, testWorkerFile))
defer func(path string) {
_ = os.RemoveAll(path)
}(filepath.Join(workSpacePath, "a.out"))
dir := "/remote"
rule := fmt.Sprintf("gcc %s", filepath.Join(dir, testWorkerFile))
targets := []string{
filepath.Join(dir, testWorkerFile),
}
id := "00:11:22:33:44:55-1737170443"
_, err := s.runBuild(rule, targets, id)
assert.Equal(t, nil, err)
}