Skip to content

Commit f5dc721

Browse files
committed
Full test coverage for convert compatibility cmd
Signed-off-by: Max Proske <[email protected]>
1 parent 5e2abb6 commit f5dc721

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

cmd/compatibility/convert_test.go

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
package compatibility
1818

1919
import (
20+
"os"
21+
"os/exec"
2022
"testing"
2123

2224
"gotest.tools/v3/assert"
2325
)
2426

2527
func Test_convert(t *testing.T) {
2628
tests := []struct {
27-
name string
28-
args []string
29-
want []string
29+
name string
30+
args []string
31+
want []string
32+
wantErr bool
3033
}{
3134
{
3235
name: "compose only",
@@ -93,11 +96,35 @@ func Test_convert(t *testing.T) {
9396
args: []string{"--project-name", "compose", "down", "--remove-orphans"},
9497
want: []string{"compose", "--project-name", "compose", "down", "--remove-orphans"},
9598
},
99+
{
100+
name: "completion command",
101+
args: []string{"__complete", "up"},
102+
want: []string{"__complete", "compose", "up"},
103+
},
104+
{
105+
name: "string flag without argument",
106+
args: []string{"--log-level"},
107+
wantErr: true,
108+
},
96109
}
97110
for _, tt := range tests {
98111
t.Run(tt.name, func(t *testing.T) {
99-
got := Convert(tt.args)
100-
assert.DeepEqual(t, tt.want, got)
112+
if tt.wantErr {
113+
if os.Getenv("BE_CRASHER") == "1" {
114+
Convert(tt.args)
115+
return
116+
}
117+
cmd := exec.Command(os.Args[0], "-test.run=^"+t.Name()+"$")
118+
cmd.Env = append(os.Environ(), "BE_CRASHER=1")
119+
err := cmd.Run()
120+
if e, ok := err.(*exec.ExitError); ok && !e.Success() {
121+
return
122+
}
123+
t.Fatalf("process ran with err %v, want exit status 1", err)
124+
} else {
125+
got := Convert(tt.args)
126+
assert.DeepEqual(t, tt.want, got)
127+
}
101128
})
102129
}
103130
}

0 commit comments

Comments
 (0)