-
Notifications
You must be signed in to change notification settings - Fork 1
/
remove.test.js
63 lines (58 loc) · 2.03 KB
/
remove.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
import * as rules from "./rules.js"
import {
INPUT_TOKEN_ENV_VAR_NAME,
gitConfigList,
runIndex,
runRemove,
} from "./testutil"
// These need to be sync'd in index.test.js
const TOKEN = "example-token"
const SERVER = "example.com"
describe("cleanup", () => {
beforeAll(() => {
// Make sure we create our entries since we can't guarantee test suite
// execution order
process.env[INPUT_TOKEN_ENV_VAR_NAME] = TOKEN
process.env["INPUT_SERVER"] = SERVER
return runIndex()
})
it("actually has the rules in place", () => {
return gitConfigList().then((output) => {
const rule = rules.make(TOKEN, SERVER).auth_rule
let lines = output.filter((line) =>
line.match(new RegExp(`${rule}=.*`)),
)
expect(lines.length).toEqual(2)
lines = output.filter((line) =>
line.match(new RegExp(`${rule}=git@${SERVER}:`)),
)
expect(lines.length).toEqual(1)
lines = output.filter((line) =>
line.match(new RegExp(`${rule}=https://${SERVER}/`)),
)
expect(lines.length).toEqual(1)
})
})
it("runs without error", () => {
const conf = rules.make(TOKEN, SERVER)
process.env["STATE_git_config_section"] = conf.section
return runRemove()
})
it("removed the rules we inserted", () => {
return gitConfigList().then((output) => {
const rule = rules.make(TOKEN, SERVER).auth_rule
let lines = output.filter((line) =>
line.match(new RegExp(`${rule}=.*`)),
)
expect(lines.length).toEqual(0)
lines = output.filter((line) =>
line.match(new RegExp(`${rule}=git@${SERVER}:`)),
)
expect(lines.length).toEqual(0)
lines = output.filter((line) =>
line.match(new RegExp(`${rule}=https://${SERVER}/`)),
)
expect(lines.length).toEqual(0)
})
})
})