Skip to content

Commit 8443536

Browse files
matejsemancikclaude
andcommitted
refactor(test): Use BATS_TEST_DIRNAME for proper path resolution in tests
Update all BATS test files to use $BATS_TEST_DIRNAME variable instead of relative paths for script execution. This ensures tests can be reliably run from any directory and follows BATS best practices. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ab97d6c commit 8443536

File tree

6 files changed

+83
-116
lines changed

6 files changed

+83
-116
lines changed

.github/actions/jira-transition-tickets/test/test_extract-issue-keys.bats

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,147 +13,147 @@ teardown() {
1313
}
1414

1515
@test "extract-issue-keys: handles empty input" {
16-
run ../scripts/extract-issue-keys.sh ""
16+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" ""
1717

1818
[ "$status" -eq 0 ]
1919
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "" ]
2020
}
2121

2222
@test "extract-issue-keys: extracts single JIRA key from branch" {
23-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123-add-feature"
23+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123-add-feature"
2424

2525
[ "$status" -eq 0 ]
2626
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123" ]
2727
}
2828

2929
@test "extract-issue-keys: extracts single JIRA key from branch with just issue key" {
30-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123"
30+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123"
3131

3232
[ "$status" -eq 0 ]
3333
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123" ]
3434
}
3535

3636
@test "extract-issue-keys: extracts multiple JIRA keys from single branch" {
37-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123-PROJ-456-combine"
37+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123-PROJ-456-combine"
3838

3939
[ "$status" -eq 0 ]
4040
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123,PROJ-456" ]
4141
}
4242

4343
@test "extract-issue-keys: extracts keys from multiple branches" {
44-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123-feature,bugfix/PROJ-456-fix"
44+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123-feature,bugfix/PROJ-456-fix"
4545

4646
[ "$status" -eq 0 ]
4747
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123,PROJ-456" ]
4848
}
4949

5050
@test "extract-issue-keys: removes duplicate JIRA keys" {
51-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123-feature,bugfix/PROJ-123-fix"
51+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123-feature,bugfix/PROJ-123-fix"
5252

5353
[ "$status" -eq 0 ]
5454
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123" ]
5555
}
5656

5757
@test "extract-issue-keys: handles branch without JIRA key" {
58-
run ../scripts/extract-issue-keys.sh "feature/some-feature"
58+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/some-feature"
5959

6060
[ "$status" -eq 0 ]
6161
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "" ]
6262
}
6363

6464
@test "extract-issue-keys: handles mixed branches (with and without keys)" {
65-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123-feature,hotfix/some-fix,bugfix/PROJ-456-bug"
65+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123-feature,hotfix/some-fix,bugfix/PROJ-456-bug"
6666

6767
[ "$status" -eq 0 ]
6868
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123,PROJ-456" ]
6969
}
7070

7171
@test "extract-issue-keys: handles whitespace in branch names" {
72-
run ../scripts/extract-issue-keys.sh " feature/PROJ-123-feature , bugfix/PROJ-456-fix "
72+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" " feature/PROJ-123-feature , bugfix/PROJ-456-fix "
7373

7474
[ "$status" -eq 0 ]
7575
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123,PROJ-456" ]
7676
}
7777

7878
@test "extract-issue-keys: extracts keys with different project prefixes" {
79-
run ../scripts/extract-issue-keys.sh "feature/ABC-123-DEF-456-GHI-789"
79+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/ABC-123-DEF-456-GHI-789"
8080

8181
[ "$status" -eq 0 ]
8282
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "ABC-123,DEF-456,GHI-789" ]
8383
}
8484

8585
@test "extract-issue-keys: extracts JIRA key at start of branch name" {
86-
run ../scripts/extract-issue-keys.sh "PROJ-123-feature-branch"
86+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "PROJ-123-feature-branch"
8787

8888
[ "$status" -eq 0 ]
8989
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123" ]
9090
}
9191

9292
@test "extract-issue-keys: extracts JIRA key in middle of branch name" {
93-
run ../scripts/extract-issue-keys.sh "feature-PROJ-123-branch"
93+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature-PROJ-123-branch"
9494

9595
[ "$status" -eq 0 ]
9696
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123" ]
9797
}
9898

9999
@test "extract-issue-keys: extracts JIRA key at end of branch name" {
100-
run ../scripts/extract-issue-keys.sh "feature-branch-PROJ-123"
100+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature-branch-PROJ-123"
101101

102102
[ "$status" -eq 0 ]
103103
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123" ]
104104
}
105105

106106
@test "extract-issue-keys: ignores lowercase project codes" {
107-
run ../scripts/extract-issue-keys.sh "feature/proj-123-test"
107+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/proj-123-test"
108108

109109
[ "$status" -eq 0 ]
110110
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "" ]
111111
}
112112

113113
@test "extract-issue-keys: handles special characters in branch names" {
114-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123_with_underscores,bugfix/PROJ-456-with-dashes"
114+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123_with_underscores,bugfix/PROJ-456-with-dashes"
115115

116116
[ "$status" -eq 0 ]
117117
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123,PROJ-456" ]
118118
}
119119

120120
@test "extract-issue-keys: handles multiple branches with sorting" {
121-
run ../scripts/extract-issue-keys.sh "PROJ-3,PROJ-1,PROJ-2"
121+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "PROJ-3,PROJ-1,PROJ-2"
122122

123123
[ "$status" -eq 0 ]
124124
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-1,PROJ-2,PROJ-3" ]
125125
}
126126

127127
@test "extract-issue-keys: handles duplicate keys in same branch" {
128-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123-and-PROJ-123-again"
128+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123-and-PROJ-123-again"
129129

130130
[ "$status" -eq 0 ]
131131
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123" ]
132132
}
133133

134134
@test "extract-issue-keys: handles complex multi-branch scenario with duplicates" {
135-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123-ABC-456,bugfix/PROJ-123-DEF-789,hotfix/ABC-456"
135+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123-ABC-456,bugfix/PROJ-123-DEF-789,hotfix/ABC-456"
136136

137137
[ "$status" -eq 0 ]
138138
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "ABC-456,DEF-789,PROJ-123" ]
139139
}
140140

141141
@test "extract-issue-keys: handles JIRA keys with large numbers" {
142-
run ../scripts/extract-issue-keys.sh "feature/PROJ-999999-test"
142+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-999999-test"
143143

144144
[ "$status" -eq 0 ]
145145
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-999999" ]
146146
}
147147

148148
@test "extract-issue-keys: handles JIRA keys with short project codes" {
149-
run ../scripts/extract-issue-keys.sh "feature/AB-123-test"
149+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/AB-123-test"
150150

151151
[ "$status" -eq 0 ]
152152
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "AB-123" ]
153153
}
154154

155155
@test "extract-issue-keys: handles multiple commas in input" {
156-
run ../scripts/extract-issue-keys.sh "feature/PROJ-123,,,bugfix/PROJ-456"
156+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/PROJ-123,,,bugfix/PROJ-456"
157157

158158
[ "$status" -eq 0 ]
159159
result="$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)"
@@ -163,22 +163,22 @@ teardown() {
163163
}
164164

165165
@test "extract-issue-keys: handles branch with slash in name" {
166-
run ../scripts/extract-issue-keys.sh "feature/team/PROJ-123-description"
166+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/team/PROJ-123-description"
167167

168168
[ "$status" -eq 0 ]
169169
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ-123" ]
170170
}
171171

172172
@test "extract-issue-keys: handles number in project identifier" {
173-
run ../scripts/extract-issue-keys.sh "feature/team/PROJ25-123-description"
173+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/team/PROJ25-123-description"
174174

175175
[ "$status" -eq 0 ]
176176
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ25-123" ]
177177
}
178178

179179

180180
@test "extract-issue-keys: handles multiple issue keys with number in project identifier" {
181-
run ../scripts/extract-issue-keys.sh "feature/team/PROJ25-123-description,feature/PROJ25-456-description"
181+
run "$BATS_TEST_DIRNAME/../scripts/extract-issue-keys.sh" "feature/team/PROJ25-123-description,feature/PROJ25-456-description"
182182

183183
[ "$status" -eq 0 ]
184184
[ "$(grep '^issue_keys=' "$GITHUB_OUTPUT" | cut -d= -f2)" = "PROJ25-123,PROJ25-456" ]

0 commit comments

Comments
 (0)