forked from mondeja/pr-linked-issues-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest
More file actions
executable file
·110 lines (93 loc) · 2.29 KB
/
test
File metadata and controls
executable file
·110 lines (93 loc) · 2.29 KB
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
#!/usr/bin/env sh
export INPUT_REPOSITORY_OWNER="mondeja"
export INPUT_REPOSITORY_NAME="pr-linked-issues-action-testing"
export GITHUB_OUTPUT="/tmp/github-output.txt"
checkDependencies() {
if [ -z "$(command -v "shunit2")" ]; then
printf "You need to install shunit2 or add it to PATH to run tests.\n" >&2
exit 1
fi
}
checkEnvironmentVariables() {
if [ -z "$GITHUB_TOKEN" ]; then
printf "You need to define the environment variable GITHUB_TOKEN to run tests.\n" >&2
exit 1
fi
}
getOutput() {
cat "$GITHUB_OUTPUT"
}
testNoLinkedPRs() {
INPUT_PULL_REQUEST=5 ./entrypoint
assertEquals "issues=" "$(getOutput)"
}
testLinkedPR() {
INPUT_PULL_REQUEST=4 ./entrypoint
assertEquals "issues=1" "$(getOutput)"
}
testLinkedPRs() {
INPUT_PULL_REQUEST=3 ./entrypoint
assertEquals "issues=1,2" "$(getOutput)"
}
testLinkedPRsOwners() {
INPUT_PULL_REQUEST=6 INPUT_OWNERS=true ./entrypoint
assertEquals \
"issues=1,2,7
opener=7
others=1,2" \
"$(getOutput)"
}
testLinkedPRsOwnersNoOthers() {
INPUT_PULL_REQUEST=3 INPUT_OWNERS=true ./entrypoint
assertEquals \
"issues=1,2
opener=1,2
others=" \
"$(getOutput)"
}
testLinkedPRsByContent() {
INPUT_PULL_REQUEST=8 INPUT_ADD_LINKS_BY_CONTENT="
**Closes**: #{issue_number}
fishes #{issue_number}
humancipates #{issue_number}
makes #{issue_number} crazy
resolves #{issue_number} even if not exists
[{issue_number}]
...{issue_number}..
\${issue_number}^
({issue_number})
#
# Lines starting with '#' character must be ignored
#
{{issue_number}}
|{issue_number}|" ./entrypoint
assertEquals \
"issues=0,2,7,34,55,57,58,59,60,65,77" \
"$(getOutput)"
}
testLinkedPrsByContentOwners() {
INPUT_OWNERS=true INPUT_PULL_REQUEST=8 INPUT_ADD_LINKS_BY_CONTENT="
**Closes**: #{issue_number}
fishes #{issue_number}" ./entrypoint
assertEquals \
"issues=2,7,34
opener=7
others=2
null=34" \
"$(getOutput)"
}
testLinkPrsByContentDontContainPlaceholder() {
assertEquals \
"The line 'foo' of the input 'add_links_by_content' does not contains the '{issue_number}' placeholder." \
"$(INPUT_PULL_REQUEST=8 INPUT_ADD_LINKS_BY_CONTENT="foo" ./entrypoint 2>&1 1>/dev/null)"
}
# Called before every test function is executed
setUp() {
rm -f "$GITHUB_OUTPUT"
}
main() {
checkDependencies
checkEnvironmentVariables
. shunit2
}
main