Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/gitpod-protocol/src/gitpod-file-parser.spec.ts
2498 views
1
/**
2
* Copyright (c) 2020 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { suite, test } from "@testdeck/mocha";
8
import * as chai from "chai";
9
10
import { WorkspaceConfig } from "./protocol";
11
import { GitpodFileParser } from "./gitpod-file-parser";
12
13
const expect = chai.expect;
14
15
const DEFAULT_IMAGE = "default-image";
16
const DEFAULT_CONFIG = <WorkspaceConfig>{ image: DEFAULT_IMAGE };
17
18
@suite
19
class TestGitpodFileParser {
20
protected parser: GitpodFileParser;
21
22
public before() {
23
this.parser = new GitpodFileParser();
24
}
25
26
@test public testOnlyOnePort() {
27
const content = `ports:\n` + ` - port: 5555`;
28
29
const result = this.parser.parse(content, {}, DEFAULT_CONFIG);
30
expect(result.config).to.deep.equal({
31
ports: [
32
{
33
port: 5555,
34
},
35
],
36
image: DEFAULT_IMAGE,
37
});
38
}
39
40
@test public testPortRange() {
41
const content = `ports:\n` + ` - port: 5555\n` + ` - port: 3000-3999`; // should be filtered out by default
42
43
const result = this.parser.parse(content, {}, DEFAULT_CONFIG);
44
expect(result.config).to.deep.equal({
45
ports: [
46
{
47
port: 5555,
48
},
49
],
50
image: DEFAULT_IMAGE,
51
});
52
}
53
54
@test public testPortRangeAccepted() {
55
const content = `ports:\n` + ` - port: 5555\n` + ` - port: 3000-3999`; // should be included if explicitly supported
56
57
const result = this.parser.parse(content, { acceptPortRanges: true }, DEFAULT_CONFIG);
58
expect(result.config).to.deep.equal({
59
ports: [
60
{
61
port: 5555,
62
},
63
{
64
port: "3000-3999",
65
},
66
],
67
image: DEFAULT_IMAGE,
68
});
69
}
70
71
@test public testSimpleTask() {
72
const content = `tasks:\n` + ` - command: yarn`;
73
74
const result = this.parser.parse(content, {}, DEFAULT_CONFIG);
75
expect(result.config).to.deep.equal({
76
tasks: [
77
{
78
command: "yarn",
79
},
80
],
81
image: DEFAULT_IMAGE,
82
});
83
}
84
85
@test public testSimpleImage() {
86
const imageName = "my-test-org/my-test-image:some-tag";
87
const content = `image: "${imageName}"\n`;
88
89
const result = this.parser.parse(content);
90
expect(result.config).to.deep.equal({
91
image: imageName,
92
});
93
}
94
95
@test public testComplexImageWithoutContext() {
96
const dockerFileName = "Dockerfile";
97
const content = `image:\n file: ${dockerFileName}\n`;
98
99
const result = this.parser.parse(content);
100
expect(result.config).to.deep.equal({
101
image: {
102
file: dockerFileName,
103
},
104
});
105
}
106
107
@test public testComplexImageWithContext() {
108
const dockerFileName = "Dockerfile";
109
const dockerContext = "docker";
110
const content = `image:\n file: ${dockerFileName}\n context: ${dockerContext}\n`;
111
112
const result = this.parser.parse(content);
113
expect(result.config).to.deep.equal({
114
image: {
115
file: dockerFileName,
116
context: dockerContext,
117
},
118
});
119
}
120
121
@test public testGitconfig() {
122
const content = `
123
gitConfig:
124
core.autocrlf: input
125
`;
126
127
const result = this.parser.parse(content, {}, DEFAULT_CONFIG);
128
expect(result.config).to.deep.equal({
129
gitConfig: {
130
"core.autocrlf": "input",
131
},
132
image: DEFAULT_IMAGE,
133
});
134
}
135
136
@test public testBrokenConfig() {
137
const content = `image: 42\n`;
138
139
const result = this.parser.parse(content, {}, DEFAULT_CONFIG);
140
expect(result.config).to.deep.equal({
141
image: DEFAULT_IMAGE,
142
});
143
}
144
}
145
module.exports = new TestGitpodFileParser(); // Only to circumvent no usage warning :-/
146
147