Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
21 changes: 19 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
89 changes: 89 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"errors"
"strings"
"testing"

"github.com/DataDog/pup/pkg/config"
)

func TestRootCmd_SilenceUsage(t *testing.T) {
Expand Down Expand Up @@ -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)
}
}