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

Function TestUsageExactArgs

internal/cmd/args_test.go:10–36  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestUsageExactArgs(t *testing.T) {
11 root := &cobra.Command{Use: "hey"}
12 cmd := &cobra.Command{Use: "threads <id>"}
13 root.AddCommand(cmd)
14
15 validator := usageExactOneArg()
16
17 if err := validator(cmd, []string{"123"}); err != nil {
18 t.Fatalf("expected nil error for valid args, got %v", err)
19 }
20
21 err := validator(cmd, nil)
22 if err == nil {
23 t.Fatal("expected error for missing args, got nil")
24 }
25 if !strings.Contains(err.Error(), "Usage: hey threads <id>") {
26 t.Fatalf("unexpected missing-args error: %q", err.Error())
27 }
28
29 err = validator(cmd, []string{"123", "456"})
30 if err == nil {
31 t.Fatal("expected error for extra args, got nil")
32 }
33 if err.Error() != "expected 1 argument, got 2" {
34 t.Fatalf("unexpected extra-args error: %q", err.Error())
35 }
36}
37
38func TestCleanUseLineStripsFlagsSuffix(t *testing.T) {
39 line := cleanUseLine("hey recordings <calendar-id> [flags]")

Callers

nothing calls this directly

Calls 2

usageExactOneArgFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected