package cmd import ( "bytes" "io" "testing" ) // TestMailCommand tests the mail CLI command structure func TestMailCommand(t *testing.T) { rootCmd := newRootCmdBase() rootCmd.SetArgs([]string{"mail", "--help"}) var buf bytes.Buffer rootCmd.SetOut(&buf) err := rootCmd.Execute() if err != nil { t.Fatalf("Mail help command failed: %v", err) } output, _ := io.ReadAll(&buf) helpText := string(output) // Verify mail subcommands are present expectedSubcommands := []string{"list", "read", "send", "delete", "trash", "draft", "search"} for _, subcmd := range expectedSubcommands { if !contains(helpText, subcmd) { t.Errorf("Mail help missing subcommand: %s", subcmd) } } } // TestMailListCommand tests the mail list subcommand func TestMailListCommand(t *testing.T) { rootCmd := newRootCmdBase() rootCmd.SetArgs([]string{"mail", "list", "--help"}) var buf bytes.Buffer rootCmd.SetOut(&buf) err := rootCmd.Execute() if err != nil { t.Fatalf("Mail list help command failed: %v", err) } output, _ := io.ReadAll(&buf) if len(output) == 0 { t.Error("Mail list help output is empty") } } // TestContactCommand tests the contact CLI command structure func TestContactCommand(t *testing.T) { rootCmd := newRootCmdBase() rootCmd.SetArgs([]string{"contact", "--help"}) var buf bytes.Buffer rootCmd.SetOut(&buf) err := rootCmd.Execute() if err != nil { t.Fatalf("Contact help command failed: %v", err) } output, _ := io.ReadAll(&buf) helpText := string(output) // Verify contact subcommands are present expectedSubcommands := []string{"list", "add", "edit", "delete"} for _, subcmd := range expectedSubcommands { if !contains(helpText, subcmd) { t.Errorf("Contact help missing subcommand: %s", subcmd) } } } // TestAttachmentCommand tests the attachment CLI command structure func TestAttachmentCommand(t *testing.T) { rootCmd := newRootCmdBase() rootCmd.SetArgs([]string{"attachment", "--help"}) var buf bytes.Buffer rootCmd.SetOut(&buf) err := rootCmd.Execute() if err != nil { t.Fatalf("Attachment help command failed: %v", err) } output, _ := io.ReadAll(&buf) helpText := string(output) // Verify attachment subcommands are present expectedSubcommands := []string{"upload", "download", "list"} for _, subcmd := range expectedSubcommands { if !contains(helpText, subcmd) { t.Errorf("Attachment help missing subcommand: %s", subcmd) } } } // TestFolderCommand tests the folder CLI command structure func TestFolderCommand(t *testing.T) { rootCmd := newRootCmdBase() rootCmd.SetArgs([]string{"folder", "--help"}) var buf bytes.Buffer rootCmd.SetOut(&buf) err := rootCmd.Execute() if err != nil { t.Fatalf("Folder help command failed: %v", err) } output, _ := io.ReadAll(&buf) helpText := string(output) // Verify folder subcommands are present expectedSubcommands := []string{"list", "create", "update", "delete"} for _, subcmd := range expectedSubcommands { if !contains(helpText, subcmd) { t.Errorf("Folder help missing subcommand: %s", subcmd) } } } // TestLabelCommand tests the label CLI command structure func TestLabelCommand(t *testing.T) { rootCmd := newRootCmdBase() rootCmd.SetArgs([]string{"label", "--help"}) var buf bytes.Buffer rootCmd.SetOut(&buf) err := rootCmd.Execute() if err != nil { t.Fatalf("Label help command failed: %v", err) } output, _ := io.ReadAll(&buf) helpText := string(output) // Verify label subcommands are present expectedSubcommands := []string{"list", "create", "update", "delete", "apply", "remove"} for _, subcmd := range expectedSubcommands { if !contains(helpText, subcmd) { t.Errorf("Label help missing subcommand: %s", subcmd) } } } // TestDraftCommand tests the draft CLI command structure func TestDraftCommand(t *testing.T) { rootCmd := newRootCmdBase() rootCmd.SetArgs([]string{"draft", "--help"}) var buf bytes.Buffer rootCmd.SetOut(&buf) err := rootCmd.Execute() if err != nil { t.Fatalf("Draft help command failed: %v", err) } output, _ := io.ReadAll(&buf) helpText := string(output) // Verify draft subcommands are present expectedSubcommands := []string{"list", "save", "edit", "send"} for _, subcmd := range expectedSubcommands { if !contains(helpText, subcmd) { t.Errorf("Draft help missing subcommand: %s", subcmd) } } }