Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f371f5b

Browse files
committed
add help test
1 parent 5416b75 commit f371f5b

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

cli/jail_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,35 @@
11
package cli_test
22

33
import (
4+
"context"
45
"testing"
56

67
"github.com/coder/coder/v2/cli/clitest"
8+
"github.com/coder/coder/v2/pty/ptytest"
9+
"github.com/coder/coder/v2/testutil"
10+
jailcli "github.com/coder/jail/cli"
11+
"github.com/stretchr/testify/assert"
712
)
813

914
// Actually testing the functionality of coder/jail takes place in the
1015
// coder/jail repo, since it's a dependency of coder.
1116
// Here we want to test basically that integrating it as a subcommand doesn't break anything.
1217
func TestJailSubcommand(t *testing.T) {
13-
_, _ = clitest.New(t, "jail", "--help")
18+
inv, _ := clitest.New(t, "jail", "--help")
19+
pty := ptytest.New(t).Attach(inv)
20+
ctx, cancelFunc := context.WithTimeout(context.Background(), testutil.WaitShort)
21+
defer cancelFunc()
22+
done := make(chan any)
23+
go func() {
24+
errC := inv.WithContext(ctx).Run()
25+
assert.NoError(t, errC)
26+
close(done)
27+
}()
28+
29+
// Expect the --help output to include the short description.
30+
// We're simply confirming that `coder jail --help` ran without a runtime error as
31+
// a good chunk of serpents self validation logic happens at runtime.
32+
pty.ExpectMatch(jailcli.BaseCommand().Short)
33+
cancelFunc()
34+
<-done
1435
}

0 commit comments

Comments
 (0)