diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 43c65f68..ca1d69e3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,6 +137,7 @@ jobs: - name: Comment on PR if: github.event_name == 'pull_request' + continue-on-error: true # Don't fail CI if comment posting fails uses: actions/github-script@v8 env: COMMENT_BODY: ${{ steps.comment.outputs.comment_body }} diff --git a/cmd/root.go b/cmd/root.go index 1893916b..f84473c6 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -207,8 +207,25 @@ var testCmd = &cobra.Command{ fmt.Println("Configuration is valid:") fmt.Printf(" Site: %s\n", cfg.Site) - fmt.Printf(" API Key: %s...%s\n", cfg.APIKey[:8], cfg.APIKey[len(cfg.APIKey)-4:]) - fmt.Printf(" App Key: %s...%s\n", cfg.AppKey[:8], cfg.AppKey[len(cfg.AppKey)-4:]) + + // Display API key info if present + if len(cfg.APIKey) >= 12 { + fmt.Printf(" API Key: %s...%s\n", cfg.APIKey[:8], cfg.APIKey[len(cfg.APIKey)-4:]) + } else if len(cfg.APIKey) > 0 { + fmt.Printf(" API Key: %s (too short - may be invalid)\n", cfg.APIKey) + } else { + fmt.Println(" API Key: (not set - using OAuth2 or will prompt)") + } + + // Display App key info if present + if len(cfg.AppKey) >= 12 { + fmt.Printf(" App Key: %s...%s\n", cfg.AppKey[:8], cfg.AppKey[len(cfg.AppKey)-4:]) + } else if len(cfg.AppKey) > 0 { + fmt.Printf(" App Key: %s (too short - may be invalid)\n", cfg.AppKey) + } else { + fmt.Println(" App Key: (not set - using OAuth2 or will prompt)") + } + fmt.Println("\nConnection test successful!") return nil diff --git a/cmd/root_test.go b/cmd/root_test.go index c171347d..d24bcbd0 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -9,6 +9,8 @@ import ( "errors" "strings" "testing" + + "github.com/DataDog/pup/pkg/config" ) func TestRootCmd_SilenceUsage(t *testing.T) { @@ -229,3 +231,90 @@ func TestFormatAPIError_AllStatusCodes(t *testing.T) { }) } } + +func TestTestCmd_EmptyKeys(t *testing.T) { + // Save original config + origCfg := cfg + + // Set up test config with empty keys + cfg = &config.Config{ + Site: "datadoghq.com", + APIKey: "", + AppKey: "", + } + defer func() { cfg = origCfg }() + + // Execute test command + err := testCmd.RunE(testCmd, []string{}) + + // Should not panic and should succeed + if err != nil { + t.Errorf("testCmd.RunE() with empty keys failed: %v", err) + } +} + +func TestTestCmd_ShortKeys(t *testing.T) { + // Save original config + origCfg := cfg + + // Set up test config with short keys + cfg = &config.Config{ + Site: "datadoghq.com", + APIKey: "short", + AppKey: "key", + } + defer func() { cfg = origCfg }() + + // Execute test command + err := testCmd.RunE(testCmd, []string{}) + + // Should not panic and should succeed + if err != nil { + t.Errorf("testCmd.RunE() with short keys failed: %v", err) + } +} + +func TestTestCmd_ValidKeys(t *testing.T) { + // Save original config + origCfg := cfg + + // Set up test config with valid length keys + cfg = &config.Config{ + Site: "datadoghq.com", + APIKey: "1234567890abcdef1234567890abcdef", + AppKey: "abcdefghijklmnopqrstuvwxyz123456", + } + defer func() { cfg = origCfg }() + + // Execute test command + err := testCmd.RunE(testCmd, []string{}) + + // Should not panic and should succeed + if err != nil { + t.Errorf("testCmd.RunE() with valid keys failed: %v", err) + } +} + +func TestTestCmd_InvalidSite(t *testing.T) { + // Save original config + origCfg := cfg + + // Set up test config with empty site + cfg = &config.Config{ + Site: "", + APIKey: "1234567890abcdef", + AppKey: "abcdefghijklmnop", + } + defer func() { cfg = origCfg }() + + // Execute test command + err := testCmd.RunE(testCmd, []string{}) + + // Should fail validation + if err == nil { + t.Error("testCmd.RunE() with empty site should fail") + } + if !strings.Contains(err.Error(), "DD_SITE") { + t.Errorf("testCmd.RunE() error should mention DD_SITE, got: %v", err) + } +}