|
17 | 17 | package compatibility |
18 | 18 |
|
19 | 19 | import ( |
| 20 | + "os" |
| 21 | + "os/exec" |
20 | 22 | "testing" |
21 | 23 |
|
22 | 24 | "gotest.tools/v3/assert" |
23 | 25 | ) |
24 | 26 |
|
25 | 27 | func Test_convert(t *testing.T) { |
26 | 28 | tests := []struct { |
27 | | - name string |
28 | | - args []string |
29 | | - want []string |
| 29 | + name string |
| 30 | + args []string |
| 31 | + want []string |
| 32 | + wantErr bool |
30 | 33 | }{ |
31 | 34 | { |
32 | 35 | name: "compose only", |
@@ -93,11 +96,35 @@ func Test_convert(t *testing.T) { |
93 | 96 | args: []string{"--project-name", "compose", "down", "--remove-orphans"}, |
94 | 97 | want: []string{"compose", "--project-name", "compose", "down", "--remove-orphans"}, |
95 | 98 | }, |
| 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 | + }, |
96 | 109 | } |
97 | 110 | for _, tt := range tests { |
98 | 111 | 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 | + } |
101 | 128 | }) |
102 | 129 | } |
103 | 130 | } |
0 commit comments