File tree Expand file tree Collapse file tree 6 files changed +63
-5
lines changed Expand file tree Collapse file tree 6 files changed +63
-5
lines changed Original file line number Diff line number Diff line change 14
14
runs-on : ubuntu-latest
15
15
steps :
16
16
- name : harden runner
17
- uses : step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4 .1
17
+ uses : step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8 .1
18
18
with :
19
19
egress-policy : block
20
20
disable-sudo : true
26
26
raw.githubusercontent.com:443
27
27
objects.githubusercontent.com:443
28
28
proxy.golang.org:443
29
+ blob.core.windows.net:443
29
30
- name : checkout code
30
- uses : actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
31
+ uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
31
32
- name : setup go
32
33
uses : actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
33
34
with :
Original file line number Diff line number Diff line change 27
27
raw.githubusercontent.com:443
28
28
objects.githubusercontent.com:443
29
29
proxy.golang.org:443
30
+ blob.core.windows.net:443
30
31
- name : checkout code
31
32
uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
32
33
- name : setup go
Original file line number Diff line number Diff line change 18
18
runs-on : ${{ matrix.os }}
19
19
steps :
20
20
- name : harden runner
21
- uses : step-security/harden-runner@55d479fb1c5bcad5a4f9099a5d9f37c8857b2845 # v2.4 .1
21
+ uses : step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8 .1
22
22
with :
23
23
egress-policy : block
24
24
disable-sudo : true
29
29
raw.githubusercontent.com:443
30
30
objects.githubusercontent.com:443
31
31
proxy.golang.org:443
32
+ blob.core.windows.net:443
32
33
- name : checkout code
33
- uses : actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
34
+ uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
34
35
- name : setup go
35
36
uses : actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
36
37
with :
Original file line number Diff line number Diff line change @@ -166,9 +166,13 @@ func newAssertions(
166
166
outPipe * bytes.Buffer ,
167
167
errPipe * bytes.Buffer ,
168
168
) api.Assertions {
169
+ expExitCode := 0
170
+ if e != nil {
171
+ expExitCode = e .ExitCode
172
+ }
169
173
a := & assertions {
170
174
failures : []error {},
171
- expExitCode : exitCode ,
175
+ expExitCode : expExitCode ,
172
176
exitCode : exitCode ,
173
177
}
174
178
if e != nil {
Original file line number Diff line number Diff line change 9
9
"bytes"
10
10
"context"
11
11
"flag"
12
+ "fmt"
12
13
"os"
13
14
"os/exec"
14
15
"path/filepath"
@@ -71,6 +72,52 @@ func TestExitCode(t *testing.T) {
71
72
require .Nil (err )
72
73
}
73
74
75
+ func TestFailExecExitCodeNotSpecified (t * testing.T ) {
76
+ if ! * failFlag {
77
+ t .Skip ("skipping without -fail flag" )
78
+ }
79
+ require := require .New (t )
80
+
81
+ fp := filepath .Join ("testdata" , "ls-fail-no-exit-code.yaml" )
82
+ f , err := os .Open (fp )
83
+ require .Nil (err )
84
+
85
+ s , err := scenario .FromReader (
86
+ f ,
87
+ scenario .WithPath (fp ),
88
+ )
89
+ require .Nil (err )
90
+ require .NotNil (s )
91
+
92
+ ctx := gdtcontext .New (gdtcontext .WithDebug ())
93
+ err = s .Run (ctx , t )
94
+ require .Nil (err )
95
+ }
96
+
97
+ func TestExecFailExitCodeNotSpecified (t * testing.T ) {
98
+ require := require .New (t )
99
+ target := os .Args [0 ]
100
+ failArgs := []string {
101
+ "-test.v" ,
102
+ "-test.run=FailExecExitCodeNotSpecified" ,
103
+ "-fail" ,
104
+ }
105
+ outerr , err := exec .Command (target , failArgs ... ).CombinedOutput ()
106
+
107
+ // The test should have failed...
108
+ require .NotNil (err )
109
+ debugout := string (outerr )
110
+ ec := 2
111
+ // Yay, different exit codes for the same not found error...
112
+ if runtime .GOOS == "darwin" {
113
+ ec = 1
114
+ }
115
+ msg := fmt .Sprintf (
116
+ "assertion failed: not equal: expected 0 but got %d" , ec ,
117
+ )
118
+ require .Contains (debugout , msg )
119
+ }
120
+
74
121
func TestShellList (t * testing.T ) {
75
122
require := require .New (t )
76
123
Original file line number Diff line number Diff line change
1
+ name : ls-fail-no-exit-code
2
+ description : a scenario that runs the `ls` command with a non-0 exit code and no assertion on exit code
3
+ tests :
4
+ - exec : ls /this/dir/does/not/exist
You can’t perform that action at this time.
0 commit comments