forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_test.go
153 lines (137 loc) · 3.2 KB
/
task_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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package atc_test
import (
. "github.com/concourse/atc"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("TaskConfig", func() {
Describe("validating", func() {
validConfig := TaskConfig{
Platform: "linux",
Run: TaskRunConfig{
Path: "reboot",
},
}
var invalidConfig TaskConfig
BeforeEach(func() {
invalidConfig = validConfig
})
Context("when platform is missing", func() {
BeforeEach(func() {
invalidConfig.Platform = ""
})
It("returns an error", func() {
Ω(invalidConfig.Validate()).Should(MatchError(ContainSubstring("missing 'platform'")))
})
})
Context("when run is missing", func() {
BeforeEach(func() {
invalidConfig.Run.Path = ""
})
It("returns an error", func() {
Ω(invalidConfig.Validate()).Should(MatchError(ContainSubstring("missing path to executable to run")))
})
})
})
Describe("merging", func() {
It("merges params while preserving other properties", func() {
Ω(TaskConfig{
Image: "some-image",
Params: map[string]string{
"FOO": "1",
"BAR": "2",
},
}.Merge(TaskConfig{
Params: map[string]string{
"FOO": "3",
"BAZ": "4",
},
})).Should(Equal(TaskConfig{
Image: "some-image",
Params: map[string]string{
"FOO": "3",
"BAR": "2",
"BAZ": "4",
},
}))
})
It("merges tags", func() {
Ω(TaskConfig{
Tags: []string{"a", "b"},
}.Merge(TaskConfig{
Tags: []string{"b", "c", "d"},
}).Tags).Should(ConsistOf("a", "b", "c", "d"))
})
It("overrides the platform", func() {
Ω(TaskConfig{
Platform: "platform-a",
}.Merge(TaskConfig{
Platform: "platform-b",
})).Should(Equal(TaskConfig{
Platform: "platform-b",
}))
})
It("overrides the image", func() {
Ω(TaskConfig{
Image: "some-image",
}.Merge(TaskConfig{
Image: "better-image",
})).Should(Equal(TaskConfig{
Image: "better-image",
}))
})
It("overrides the run config", func() {
Ω(TaskConfig{
Run: TaskRunConfig{
Path: "some-path",
Args: []string{"arg1", "arg2"},
},
}.Merge(TaskConfig{
Image: "some-image",
Run: TaskRunConfig{
Path: "better-path",
Args: []string{"better-arg1", "better-arg2"},
},
})).Should(Equal(TaskConfig{
Image: "some-image",
Run: TaskRunConfig{
Path: "better-path",
Args: []string{"better-arg1", "better-arg2"},
},
}))
})
It("overrides the run config even with no args", func() {
Ω(TaskConfig{
Run: TaskRunConfig{
Path: "some-path",
Args: []string{"arg1", "arg2"},
},
}.Merge(TaskConfig{
Image: "some-image",
Run: TaskRunConfig{
Path: "better-path",
},
})).Should(Equal(TaskConfig{
Image: "some-image",
Run: TaskRunConfig{
Path: "better-path",
},
}))
})
It("overrides input configuration", func() {
Ω(TaskConfig{
Inputs: []TaskInputConfig{
{Name: "some-input", Path: "some-destination"},
},
}.Merge(TaskConfig{
Inputs: []TaskInputConfig{
{Name: "another-input", Path: "another-destination"},
},
})).Should(Equal(TaskConfig{
Inputs: []TaskInputConfig{
{Name: "another-input", Path: "another-destination"},
},
}))
})
})
})