Skip to content

Commit

Permalink
Full test coverage for convert compatibility cmd
Browse files Browse the repository at this point in the history
Signed-off-by: Max Proske <[email protected]>
  • Loading branch information
maxproske authored and glours committed Feb 5, 2025
1 parent a6a3942 commit 6ecb8d4
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions cmd/compatibility/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@
package compatibility

import (
"errors"
"os"
"os/exec"
"testing"

"gotest.tools/v3/assert"
)

func Test_convert(t *testing.T) {
tests := []struct {
name string
args []string
want []string
name string
args []string
want []string
wantErr bool
}{
{
name: "compose only",
Expand Down Expand Up @@ -93,11 +97,36 @@ func Test_convert(t *testing.T) {
args: []string{"--project-name", "compose", "down", "--remove-orphans"},
want: []string{"compose", "--project-name", "compose", "down", "--remove-orphans"},
},
{
name: "completion command",
args: []string{"__complete", "up"},
want: []string{"__complete", "compose", "up"},
},
{
name: "string flag without argument",
args: []string{"--log-level"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Convert(tt.args)
assert.DeepEqual(t, tt.want, got)
if tt.wantErr {
if os.Getenv("BE_CRASHER") == "1" {
Convert(tt.args)
return
}
cmd := exec.Command(os.Args[0], "-test.run=^"+t.Name()+"$")
cmd.Env = append(os.Environ(), "BE_CRASHER=1")
err := cmd.Run()
var e *exec.ExitError
if errors.As(err, &e) && !e.Success() {
return
}
t.Fatalf("process ran with err %v, want exit status 1", err)
} else {
got := Convert(tt.args)
assert.DeepEqual(t, tt.want, got)
}
})
}
}

0 comments on commit 6ecb8d4

Please sign in to comment.