-
-
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.
- Loading branch information
1 parent
a0298b1
commit 2a5f85d
Showing
2 changed files
with
57 additions
and
0 deletions.
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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLoadConfig(t *testing.T) { | ||
// Create a temporary directory for test files | ||
tmpDir, err := os.MkdirTemp("", "config_test") | ||
if err != nil { | ||
t.Fatalf("Failed to create temp directory: %v", err) | ||
} | ||
defer os.RemoveAll(tmpDir) | ||
|
||
// Create an empty file for testing | ||
configFilePath := filepath.Join(tmpDir, ".sauced.yaml") | ||
|
||
if err := os.WriteFile(configFilePath, []byte{}, 0644); err != nil { | ||
t.Fatalf("Failed to create empty file: %v", err) | ||
} | ||
|
||
// Path for a non-existent file | ||
nonExistentPath := filepath.Join(tmpDir, "non_existent.yaml") | ||
|
||
tests := []struct { | ||
name string | ||
path string | ||
fallbackPath string | ||
expectedError bool | ||
}{ | ||
{"Existing file", configFilePath, "", false}, | ||
{"Non-existent file", nonExistentPath, "", true}, | ||
{"Non-existent file with fallback", DefaultConfigPath, configFilePath, false}, | ||
{"Default path", DefaultConfigPath, "", true}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
config, err := LoadConfig(tt.path, tt.fallbackPath) | ||
|
||
if tt.expectedError { | ||
assert.Error(t, err) | ||
assert.Nil(t, config) | ||
} else { | ||
assert.NoError(t, err) | ||
assert.NotNil(t, config) | ||
} | ||
}) | ||
} | ||
} |