/
job.ts
172 lines (169 loc) · 5.42 KB
/
job.ts
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import "mocha";
import { assert } from "chai";
import * as mock from "./mock";
import {
Job,
Result,
JobHost,
JobCache,
JobStorage,
brigadeCachePath,
brigadeStoragePath,
jobNameIsValid
} from "../src/job";
describe("job", function() {
describe("jobNameIsValid", () => {
it("allows DNS-like names", function() {
let legal = ["abcdef", "ab", "a-b", "a-9", "a12345678b", "a.b"];
for (let n of legal) {
assert.isTrue(jobNameIsValid(n), "tested " + n);
}
});
it("disallows non-DNS-like names", function() {
let illegal = [
"ab-", // no trailing -
"-ab", // no leading dash
"a_b", // underscore is illegal
"ab.", // trailing dot is illegal
"A-B" // Capitals are illegal
];
for (let n of illegal) {
assert.isFalse(jobNameIsValid(n), "tested " + n);
}
});
});
describe("JobCache", function() {
describe("#constructor", function() {
it("correctly sets default values", function() {
let c = new JobCache();
assert.equal(c.path, brigadeCachePath, "Dir is /brigade/cache");
assert.isFalse(c.enabled, "disabled by default");
assert.equal(c.size, "5Mi", "size is 5mi");
});
});
describe("#setPath", function() {
it("correctly sets and gets path", function() {
let c = new JobCache();
assert.equal(c.path, brigadeCachePath, "Dir is /brigade/cache");
c.path = "/foo";
assert.equal(c.path, "/foo", "Assert dir is /foo");
});
});
});
describe("JobStorage", function() {
describe("#constructor", function() {
it("correctly sets default values", function() {
let c = new JobStorage();
assert.equal(
c.path,
brigadeStoragePath,
"Dir is " + brigadeStoragePath
);
assert.isFalse(c.enabled, "disabled by default");
});
});
describe("#setPath", function() {
it("correctly sets and gets path", function() {
let s = new JobStorage();
assert.equal(s.path, brigadeStoragePath, "Dir is /brigade/cache");
s.path = "/foo";
assert.equal(s.path, "/foo", "Assert dir is /foo");
});
});
});
describe("JobHost", function() {
describe("#constructor", function() {
it("correctly sets default values", function() {
let h = new JobHost();
assert.equal(0, h.nodeSelector.size, "had empty nodeSelector map");
// Validate that the nodeSelector structure works like a map.
h.nodeSelector.set("callMe", "Ishmael");
assert.equal("Ishmael", h.nodeSelector.get("callMe"));
});
});
});
describe("Job", function() {
let j: mock.MockJob;
describe("#constructor", function() {
it("creates a named job", function() {
j = new mock.MockJob("my-name");
assert.equal(j.name, "my-name");
});
it("starts with initialized JobHost", function() {
j = new mock.MockJob("name");
assert.equal(j.host.nodeSelector.size, 0);
});
it("longer than expected name", function(done){
try {
new mock.MockJob("justmakingthesethirtysevencharacterss");
done("Expecting to fail for more than 36 characters");
} catch (error) {
done();
}
});
context("when image is supplied", function() {
it("sets image property", function() {
j = new mock.MockJob("my-name", "alpine:3.4");
assert.equal(j.image, "alpine:3.4");
});
});
context("when imageForcePull is supplied", function() {
it("sets imageForcePull property", function() {
j = new mock.MockJob("my-name", "alpine:3.4", [], true);
assert.isTrue(j.imageForcePull);
});
});
context("when tasks are supplied", function() {
it("sets task list", function() {
j = new mock.MockJob("my", "img", ["a", "b", "c"]);
assert.deepEqual(j.tasks, ["a", "b", "c"]);
});
});
context("when serviceAccount is supplied", function() {
it("sets serviceAccount property", function() {
j = new mock.MockJob("my-name", "alpine:3.4", [], true);
j.serviceAccount = "svcAccount";
assert.equal(j.serviceAccount, "svcAccount");
});
});
});
describe("#podName", function() {
beforeEach(function() {
j = new mock.MockJob("my-job");
});
context("before run", function() {
it("is empty", function() {
assert.isUndefined(j.podName);
});
});
context("after run", function() {
it("is accessible", function(done) {
j.run().then(rez => {
assert.equal(j.podName, "generated-fake-job-name");
done();
});
});
});
});
describe("#cache", function() {
it("is disabled by default", function() {
assert.isFalse(j.cache.enabled);
});
});
describe("#storage", function() {
it("is disabled by default", function() {
assert.isFalse(j.storage.enabled);
});
});
describe("#annotations", function() {
beforeEach(function() {
j = new mock.MockJob("my-job");
});
it("is an empty list that can be written", function() {
assert.deepEqual(j.annotations, {});
j.annotations["some_kubetoiam/thing"] = "my/path";
assert.deepEqual(j.annotations, { "some_kubetoiam/thing": "my/path" });
});
});
});
});