Skip to content

Commit

Permalink
test: now there is a check for the fallback config file contents
Browse files Browse the repository at this point in the history
  • Loading branch information
nickytonline committed Sep 4, 2024
1 parent a5324ce commit 1bc689e
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"fmt"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -35,14 +36,47 @@ func TestLoadConfig(t *testing.T) {

t.Run("Non-existent file with fallback", func(t *testing.T) {
t.Parallel()
fileContents := `# Configuration for attributing commits with emails to GitHub user profiles
# Used during codeowners generation.
# List the emails associated with the given username.
# The commits associated with these emails will be attributed to
# the username in this yaml map. Any number of emails may be listed.
attribution:
brandonroberts:
- [email protected]
jpmcb:
- [email protected]
nickytonline:
- [email protected]
- [email protected]`

tmpDir := t.TempDir()
fallbackPath := filepath.Join(tmpDir, ".sauced.yaml")
require.NoError(t, os.WriteFile(fallbackPath, []byte("key: fallback"), 0644))
err := os.WriteFile(fallbackPath, []byte(fileContents), 0644)
require.NoError(t, err)

// Print out the contents of the file we just wrote
writtenData, err := os.ReadFile(fallbackPath)
require.NoError(t, err)
fmt.Printf("Contents written to file:\n%s\n", string(writtenData))

nonExistentPath := filepath.Join(tmpDir, "non-existent.yaml")

config, err := LoadConfig(nonExistentPath, fallbackPath)

fmt.Printf("Loaded config: %+v\n", config)
fmt.Printf("Error: %v\n", err)

assert.NoError(t, err)
assert.NotNil(t, config)

// Assert that config contains all the Attributions in fileContents
assert.Equal(t, 3, len(config.Attributions))

// Check specific attributions
assert.Equal(t, []string{"[email protected]"}, config.Attributions["brandonroberts"])
assert.Equal(t, []string{"[email protected]"}, config.Attributions["jpmcb"])
assert.Equal(t, []string{"[email protected]", "[email protected]"}, config.Attributions["nickytonline"])
})

t.Run("Default path", func(t *testing.T) {
Expand Down

0 comments on commit 1bc689e

Please sign in to comment.