mirror of
https://github.com/aykhans/dodo.git
synced 2025-09-07 11:30:47 +00:00
add config file parser
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -525,3 +526,83 @@ func TestMergeConfig_AppendBehavior(t *testing.T) {
|
||||
assert.Len(t, config.Proxies, originalProxies, "Empty proxies should not change existing proxies")
|
||||
})
|
||||
}
|
||||
|
||||
func TestParseConfigFile(t *testing.T) {
|
||||
t.Run("parseConfigFile with maxDepth 0", func(t *testing.T) {
|
||||
// Create a mock config file
|
||||
configFile, _ := types.ParseConfigFile("test.yaml")
|
||||
|
||||
// Since we can't actually test file reading without a real file,
|
||||
// we'll test the function's behavior with maxDepth
|
||||
config, err := parseConfigFile(*configFile, 0)
|
||||
|
||||
// The function will return an error because the file doesn't exist
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, config)
|
||||
})
|
||||
|
||||
t.Run("parseConfigFile returns ConfigFileReadError", func(t *testing.T) {
|
||||
configFile, _ := types.ParseConfigFile("/nonexistent/file.yaml")
|
||||
config, err := parseConfigFile(*configFile, 1)
|
||||
|
||||
require.Error(t, err)
|
||||
assert.Nil(t, config)
|
||||
// Check if error is of type ConfigFileReadError
|
||||
var readErr types.ConfigFileReadError
|
||||
assert.ErrorAs(t, err, &readErr)
|
||||
})
|
||||
}
|
||||
|
||||
func TestPrintValidationErrors(t *testing.T) {
|
||||
t.Run("printValidationErrors with empty value", func(t *testing.T) {
|
||||
// This function prints to stdout, so we can't easily test its output
|
||||
// But we can test that it doesn't panic
|
||||
errors := []types.FieldParseError{
|
||||
{
|
||||
Field: "test_field",
|
||||
Value: "",
|
||||
Err: errors.New("test error"),
|
||||
},
|
||||
}
|
||||
|
||||
// Should not panic
|
||||
assert.NotPanics(t, func() {
|
||||
printValidationErrors("TEST", errors...)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("printValidationErrors with value", func(t *testing.T) {
|
||||
errors := []types.FieldParseError{
|
||||
{
|
||||
Field: "test_field",
|
||||
Value: "test_value",
|
||||
Err: errors.New("test error"),
|
||||
},
|
||||
}
|
||||
|
||||
// Should not panic
|
||||
assert.NotPanics(t, func() {
|
||||
printValidationErrors("TEST", errors...)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("printValidationErrors with multiple errors", func(t *testing.T) {
|
||||
errors := []types.FieldParseError{
|
||||
{
|
||||
Field: "field1",
|
||||
Value: "value1",
|
||||
Err: errors.New("error1"),
|
||||
},
|
||||
{
|
||||
Field: "field2",
|
||||
Value: "",
|
||||
Err: errors.New("error2"),
|
||||
},
|
||||
}
|
||||
|
||||
// Should not panic
|
||||
assert.NotPanics(t, func() {
|
||||
printValidationErrors("TEST", errors...)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user