From 6bfa710843265ddb86c04cca879949455732aaaa Mon Sep 17 00:00:00 2001 From: Nate Meyer <672246+notnmeyer@users.noreply.github.com> Date: Thu, 18 Jun 2026 09:29:11 -0700 Subject: [PATCH] dedciated-sending-ips command --- cmd/dedicated_sending_ips.go | 50 +++++++++++++++++++++++++++++++ cmd/dedicated_sending_ips_test.go | 40 +++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 cmd/dedicated_sending_ips.go create mode 100644 cmd/dedicated_sending_ips_test.go diff --git a/cmd/dedicated_sending_ips.go b/cmd/dedicated_sending_ips.go new file mode 100644 index 0000000..7ac82c4 --- /dev/null +++ b/cmd/dedicated_sending_ips.go @@ -0,0 +1,50 @@ +package cmd + +import ( + "fmt" + + "github.com/loops-so/cli/internal/config" + "github.com/spf13/cobra" +) + +func runDedicatedSendingIPs(cfg *config.Config) ([]string, error) { + return newAPIClient(cfg).GetDedicatedSendingIPs() +} + +var dedicatedSendingIPsCmd = &cobra.Command{ + Use: "dedicated-sending-ips", + Short: "List dedicated sending IP addresses assigned to your team", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + cfg, err := loadConfig() + if err != nil { + return err + } + + ips, err := runDedicatedSendingIPs(cfg) + if err != nil { + return err + } + + if isJSONOutput() { + if ips == nil { + ips = []string{} + } + return printJSON(cmd.OutOrStdout(), ips) + } + + if len(ips) == 0 { + fmt.Fprintln(cmd.OutOrStdout(), "No dedicated sending IPs assigned.") + return nil + } + + for _, ip := range ips { + fmt.Fprintln(cmd.OutOrStdout(), ip) + } + return nil + }, +} + +func init() { + rootCmd.AddCommand(dedicatedSendingIPsCmd) +} diff --git a/cmd/dedicated_sending_ips_test.go b/cmd/dedicated_sending_ips_test.go new file mode 100644 index 0000000..a263835 --- /dev/null +++ b/cmd/dedicated_sending_ips_test.go @@ -0,0 +1,40 @@ +package cmd + +import ( + "net/http" + "reflect" + "testing" +) + +func TestRunDedicatedSendingIPs(t *testing.T) { + t.Run("returns assigned ips", func(t *testing.T) { + serveJSON(t, http.StatusOK, `["192.0.2.1","192.0.2.2"]`) + ips, err := runDedicatedSendingIPs(cfg(t)) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + want := []string{"192.0.2.1", "192.0.2.2"} + if !reflect.DeepEqual(ips, want) { + t.Errorf("got %+v, want %+v", ips, want) + } + }) + + t.Run("returns empty slice when none assigned", func(t *testing.T) { + serveJSON(t, http.StatusOK, `[]`) + ips, err := runDedicatedSendingIPs(cfg(t)) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if len(ips) != 0 { + t.Errorf("expected empty slice, got %+v", ips) + } + }) + + t.Run("returns error on api failure", func(t *testing.T) { + serveJSON(t, http.StatusUnauthorized, `{"error":"Invalid API key"}`) + _, err := runDedicatedSendingIPs(cfg(t)) + if err == nil { + t.Fatal("expected error, got nil") + } + }) +}