MCPcopy Create free account
hub / github.com/basecamp/hey-cli / TestValidateBoxArgs

Function TestValidateBoxArgs

internal/cmd/box_test.go:13–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestValidateBoxArgs(t *testing.T) {
14 command := &cobra.Command{Use: "box"}
15 command.SetArgs([]string{})
16
17 tests := []struct {
18 name string
19 args []string
20 wantErr bool
21 errContains string
22 }{
23 {
24 name: "missing arg",
25 args: nil,
26 wantErr: true,
27 errContains: "Usage:",
28 },
29 {
30 name: "one arg",
31 args: []string{"imbox"},
32 wantErr: false,
33 },
34 {
35 name: "too many args",
36 args: []string{"imbox", "extra"},
37 wantErr: true,
38 errContains: "expected 1 mailbox argument",
39 },
40 }
41
42 for _, tt := range tests {
43 t.Run(tt.name, func(t *testing.T) {
44 err := validateBoxArgs(command, tt.args)
45 if tt.wantErr {
46 if err == nil {
47 t.Fatalf("expected error, got nil")
48 }
49 if tt.errContains != "" && !strings.Contains(err.Error(), tt.errContains) {
50 t.Fatalf("error = %q, want substring %q", err.Error(), tt.errContains)
51 }
52 return
53 }
54
55 if err != nil {
56 t.Fatalf("unexpected error: %v", err)
57 }
58 })
59 }
60}
61
62// makePostings creates n test postings with sequential IDs starting at offset+1.
63func makePostings(n, offset int) []generated.Posting {

Callers

nothing calls this directly

Calls 2

validateBoxArgsFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected