(t *testing.T)
| 8 | ) |
| 9 | |
| 10 | func 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 | |
| 38 | func TestCleanUseLineStripsFlagsSuffix(t *testing.T) { |
| 39 | line := cleanUseLine("hey recordings <calendar-id> [flags]") |
nothing calls this directly
no test coverage detected