forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd2g_test.go
57 lines (51 loc) · 1.39 KB
/
d2g_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
package main
import (
"encoding/json"
"fmt"
"runtime"
"testing"
"github.com/mcuadros/go-defaults"
"github.com/taskcluster/taskcluster/v54/tools/d2g/dockerworker"
)
func TestWithValidDockerWorkerPayload(t *testing.T) {
setup(t)
image := map[string]interface{}{
"name": "ubuntu:latest",
"type": "docker-image",
}
imageBytes, err := json.Marshal(image)
if err != nil {
t.Fatalf("Error marshaling JSON: %v", err)
}
payload := dockerworker.DockerWorkerPayload{
Command: []string{"/bin/bash", "-c", "echo hello world"},
Image: json.RawMessage(imageBytes),
MaxRunTime: 10,
}
defaults.SetDefaults(&payload)
td := testTask(t)
switch fmt.Sprintf("%s:%s", runtime.GOOS, engine) {
case "linux:multiuser":
_ = submitAndAssert(t, td, payload, "completed", "completed")
default:
_ = submitAndAssert(t, td, payload, "exception", "malformed-payload")
}
}
func TestWithInvalidDockerWorkerPayload(t *testing.T) {
setup(t)
image := map[string]interface{}{
"name": "ubuntu:latest",
"type": "docker-image",
}
imageBytes, err := json.Marshal(image)
if err != nil {
t.Fatalf("Error marshaling JSON: %v", err)
}
payload := dockerworker.DockerWorkerPayload{
Command: []string{"/bin/bash", "-c", "echo hello world"},
Image: json.RawMessage(imageBytes),
}
defaults.SetDefaults(&payload)
td := testTask(t)
_ = submitAndAssert(t, td, payload, "exception", "malformed-payload")
}