Commit f2b8933
test: fix test execution and improve assertions
The logs tests had a critical issue preventing all test cases from
running. The production code used os.Exit(127) when syscall.Exec failed,
which terminated the entire test process after the first subtest
completed. This made gotestsum report failures and prevented
comprehensive test coverage.
Here is the error you can see in gotestsum previously:
```console
PASS pkg/cmd/tknpac/logs.TestLogs/good/show_logs (0.01s)
=== RUN TestLogs
FAIL pkg/cmd/tknpac/logs.TestLogs (-1.00s)
=== Failed
=== FAIL: pkg/cmd/tknpac/logs TestLogs (unknown)
ok github.com/openshift-pipelines/pipelines-as-code/pkg/cmd/tknpac/logs
0.009s
DONE 2 tests, 1 failure in 0.011s
```
Changes made:
- Replace os.Exit with proper error return in showlogswithtkn()
- Add execFunc variable to make syscall.Exec mockable in tests
- Mock execFunc in tests to prevent process replacement
- Upgrade to gotest.tools/v3/assert for stronger assertions
- Fix duplicate test name causing gotestsum confusion
- Remove unused "shift" field and invalid test case
- Simplify test setup by removing unnecessary exec.LookPath
gotestsum, and all linting checks pass.
Assisted-by: Claude Sonnet 4.5 (via Claude Code)1 parent ef35fcc commit f2b8933
File tree
4 files changed
+46
-30
lines changed- pkg/cmd/tknpac/logs
4 files changed
+46
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| |||
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
240 | 241 | | |
241 | 242 | | |
242 | 243 | | |
243 | | - | |
| 244 | + | |
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
| |||
257 | 258 | | |
258 | 259 | | |
259 | 260 | | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
265 | 264 | | |
266 | 265 | | |
267 | 266 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
33 | 32 | | |
34 | 33 | | |
35 | 34 | | |
36 | | - | |
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
| |||
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
45 | | - | |
46 | 43 | | |
47 | 44 | | |
48 | 45 | | |
49 | 46 | | |
50 | 47 | | |
51 | 48 | | |
52 | 49 | | |
53 | | - | |
| 50 | + | |
54 | 51 | | |
55 | 52 | | |
56 | 53 | | |
| |||
64 | 61 | | |
65 | 62 | | |
66 | 63 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | 64 | | |
80 | 65 | | |
81 | 66 | | |
| |||
119 | 104 | | |
120 | 105 | | |
121 | 106 | | |
122 | | - | |
123 | | - | |
124 | 107 | | |
125 | 108 | | |
126 | 109 | | |
| |||
130 | 113 | | |
131 | 114 | | |
132 | 115 | | |
133 | | - | |
| 116 | + | |
134 | 117 | | |
135 | 118 | | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
136 | 122 | | |
137 | 123 | | |
138 | | - | |
| 124 | + | |
139 | 125 | | |
140 | | - | |
141 | | - | |
142 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
143 | 129 | | |
144 | 130 | | |
145 | 131 | | |
| |||
0 commit comments