-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathget-project-context.test.js
147 lines (138 loc) · 3.71 KB
/
get-project-context.test.js
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
import test from "ava";
import getProjectContext from "../lib/get-project-context.js";
test("Parse project path with https URL", (t) => {
t.is(
getProjectContext({ env: {} }, "https://gitlab.com", "https://api.gitlab.com", "https://gitlab.com/owner/repo.git")
.projectPath,
"owner/repo"
);
t.is(
getProjectContext({ env: {} }, "https://gitlab.com", "https://api.gitlab.com", "https://gitlab.com/owner/repo")
.projectPath,
"owner/repo"
);
});
test("Parse project path with git URL", (t) => {
t.is(
getProjectContext(
{ env: {} },
"https://gitlab.com",
"https://api.gitlab.com",
"git+ssh://git@gitlab.com/owner/repo.git"
).projectPath,
"owner/repo"
);
t.is(
getProjectContext(
{ env: {} },
"https://gitlab.com",
"https://api.gitlab.com",
"git+ssh://git@gitlab.com/owner/repo"
).projectPath,
"owner/repo"
);
});
test("Parse project path with context in repo URL", (t) => {
t.is(
getProjectContext(
{ env: {} },
"https://gitlab.com/context",
"https://api.gitlab.com",
"https://gitlab.com/context/owner/repo.git"
).projectPath,
"owner/repo"
);
t.is(
getProjectContext(
{ env: {} },
"https://gitlab.com/context",
"https://api.gitlab.com",
"git+ssh://git@gitlab.com/context/owner/repo.git"
).projectPath,
"owner/repo"
);
});
test("Parse project path with context not in repo URL", (t) => {
t.is(
getProjectContext(
{ env: {} },
"https://gitlab.com/context",
"https://api.gitlab.com",
"https://gitlab.com/owner/repo.git"
).projectPath,
"owner/repo"
);
t.is(
getProjectContext(
{ env: {} },
"https://gitlab.com/context",
"https://api.gitlab.com",
"git+ssh://git@gitlab.com/owner/repo.git"
).projectPath,
"owner/repo"
);
});
test("Parse project path with organization and subgroup", (t) => {
t.is(
getProjectContext(
{ env: {} },
"https://gitlab.com/context",
"https://api.gitlab.com",
"https://gitlab.com/orga/subgroup/owner/repo.git"
).projectPath,
"orga/subgroup/owner/repo"
);
t.is(
getProjectContext(
{ env: {} },
"https://gitlab.com/context",
"https://api.gitlab.com",
"git+ssh://git@gitlab.com/orga/subgroup/owner/repo.git"
).projectPath,
"orga/subgroup/owner/repo"
);
});
test("Get project path from GitLab CI", (t) => {
t.is(
getProjectContext(
{ envCi: { service: "gitlab" }, env: { CI_PROJECT_PATH: "other-owner/other-repo" } },
"https://gitlab.com",
"https://api.gitlab.com",
"https://gitlab.com/owner/repo.git"
).projectPath,
"other-owner/other-repo"
);
});
test("Ignore CI_PROJECT_PATH if not on GitLab CI", (t) => {
t.is(
getProjectContext(
{ envCi: { service: "travis" }, env: { CI_PROJECT_PATH: "other-owner/other-repo" } },
"https://gitlab.com",
"https://api.gitlab.com",
"https://gitlab.com/owner/repo.git"
).projectPath,
"owner/repo"
);
});
test("Uses project API URL with project path", (t) => {
t.is(
getProjectContext(
{ envCi: { service: "gitlab" }, env: { CI_PROJECT_PATH: "other-owner/other-repo" } },
"https://gitlab.com",
"https://api.gitlab.com",
"https://gitlab.com/owner/repo.git"
).projectApiUrl,
"https://api.gitlab.com/projects/other-owner%2Fother-repo"
);
});
test("Uses project API URL with project ID", (t) => {
t.is(
getProjectContext(
{ envCi: { service: "gitlab" }, env: { CI_PROJECT_ID: "42" } },
"https://gitlab.com",
"https://api.gitlab.com",
"https://gitlab.com/owner/repo.git"
).projectApiUrl,
"https://api.gitlab.com/projects/42"
);
});