Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stympy committed Dec 10, 2024
1 parent 28eaa39 commit 330c306
Showing 1 changed file with 38 additions and 29 deletions.
67 changes: 38 additions & 29 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"log"
"os"
"path/filepath"
"testing"
Expand All @@ -20,57 +21,61 @@ func TestConfigurationLoading(t *testing.T) {
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
defer os.RemoveAll(tmpDir)
defer func() {
if err := os.RemoveAll(tmpDir); err != nil {
log.Fatalf("Failed to remove directory: %v", err)
}
}()

// Create a test config file
configContent := `
api_key: config-api-key
endpoint: https://config.honeybadger.io
`
configPath := filepath.Join(tmpDir, "honeybadger.yml")
if err := os.WriteFile(configPath, []byte(configContent), 0644); err != nil {
if err := os.WriteFile(configPath, []byte(configContent), 0600); err != nil {
t.Fatalf("Failed to write config file: %v", err)
}

tests := []struct {
name string
name string
envAPIKey string
envEndpoint string
useConfigFile bool
wantAPIKey string
wantEndpoint string
}{
{
name: "environment variables take precedence over config file",
envAPIKey: "env-api-key",
envEndpoint: "https://env.honeybadger.io",
useConfigFile: true,
wantAPIKey: "env-api-key",
wantEndpoint: "https://env.honeybadger.io",
name: "environment variables take precedence over config file",
envAPIKey: "env-api-key",
envEndpoint: "https://env.honeybadger.io",
useConfigFile: true,
wantAPIKey: "env-api-key",
wantEndpoint: "https://env.honeybadger.io",
},
{
name: "config file values used when no environment variables",
envAPIKey: "",
envEndpoint: "",
useConfigFile: true,
wantAPIKey: "config-api-key",
wantEndpoint: "https://config.honeybadger.io",
name: "config file values used when no environment variables",
envAPIKey: "",
envEndpoint: "",
useConfigFile: true,
wantAPIKey: "config-api-key",
wantEndpoint: "https://config.honeybadger.io",
},
{
name: "default values used when no config",
envAPIKey: "",
envEndpoint: "",
useConfigFile: false,
wantAPIKey: "",
wantEndpoint: "https://api.honeybadger.io",
name: "default values used when no config",
envAPIKey: "",
envEndpoint: "",
useConfigFile: false,
wantAPIKey: "",
wantEndpoint: "https://api.honeybadger.io",
},
{
name: "partial environment override",
envAPIKey: "env-api-key",
envEndpoint: "",
useConfigFile: true,
wantAPIKey: "env-api-key",
wantEndpoint: "https://config.honeybadger.io",
name: "partial environment override",
envAPIKey: "env-api-key",
envEndpoint: "",
useConfigFile: true,
wantAPIKey: "env-api-key",
wantEndpoint: "https://config.honeybadger.io",
},
}

Expand All @@ -81,8 +86,12 @@ endpoint: https://config.honeybadger.io

// Restore original environment after test
defer func() {
os.Setenv("HONEYBADGER_API_KEY", originalAPIKey)
os.Setenv("HONEYBADGER_ENDPOINT", originalEndpoint)
if err := os.Setenv("HONEYBADGER_API_KEY", originalAPIKey); err != nil {
t.Errorf("error restoring environment variable: %v", err)
}
if err := os.Setenv("HONEYBADGER_ENDPOINT", originalEndpoint); err != nil {
t.Errorf("error restoring environment variable: %v", err)
}
cfgFile = originalConfigFile
}()

Expand Down

0 comments on commit 330c306

Please sign in to comment.