-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: now there is a check for the fallback config file contents
- Loading branch information
1 parent
a5324ce
commit 1bc689e
Showing
1 changed file
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
@@ -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) { | ||
|