mirror of
https://github.com/aykhans/dodo.git
synced 2025-09-09 04:20:46 +00:00
add config file parser
This commit is contained in:
@@ -63,6 +63,25 @@ func (e FieldParseErrors) Error() string {
|
||||
return errorString
|
||||
}
|
||||
|
||||
type UnmarshalError struct {
|
||||
error error
|
||||
}
|
||||
|
||||
func NewUnmarshalError(err error) UnmarshalError {
|
||||
if err == nil {
|
||||
err = ErrNoError
|
||||
}
|
||||
return UnmarshalError{err}
|
||||
}
|
||||
|
||||
func (e UnmarshalError) Error() string {
|
||||
return "Unmarshal error: " + e.error.Error()
|
||||
}
|
||||
|
||||
func (e UnmarshalError) Unwrap() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// ======================================== CLI ========================================
|
||||
|
||||
type CLIUnexpectedArgsError struct {
|
||||
|
@@ -205,20 +205,50 @@ func TestNewRemoteConfigFileParseError(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestErrorConstants(t *testing.T) {
|
||||
t.Run("ErrNoError has correct message", func(t *testing.T) {
|
||||
expected := "no error (internal)"
|
||||
assert.Equal(t, expected, ErrNoError.Error())
|
||||
func TestUnmarshalError_Error(t *testing.T) {
|
||||
t.Run("Error returns formatted message", func(t *testing.T) {
|
||||
originalErr := errors.New("yaml parsing failed")
|
||||
err := NewUnmarshalError(originalErr)
|
||||
|
||||
expected := "Unmarshal error: yaml parsing failed"
|
||||
assert.Equal(t, expected, err.Error())
|
||||
})
|
||||
|
||||
t.Run("ErrCLINoArgs has correct message", func(t *testing.T) {
|
||||
expected := "CLI expects arguments but received none"
|
||||
assert.Equal(t, expected, ErrCLINoArgs.Error())
|
||||
t.Run("Error with nil underlying error", func(t *testing.T) {
|
||||
err := NewUnmarshalError(nil)
|
||||
|
||||
expected := "Unmarshal error: no error (internal)"
|
||||
assert.Equal(t, expected, err.Error())
|
||||
})
|
||||
}
|
||||
|
||||
func TestUnmarshalError_Unwrap(t *testing.T) {
|
||||
t.Run("Unwrap returns original error", func(t *testing.T) {
|
||||
originalErr := errors.New("original error")
|
||||
err := NewUnmarshalError(originalErr)
|
||||
|
||||
assert.Equal(t, originalErr, err.Unwrap())
|
||||
})
|
||||
|
||||
t.Run("ErrCLIUnexpectedArgs has correct message", func(t *testing.T) {
|
||||
expected := "CLI received unexpected arguments"
|
||||
assert.Equal(t, expected, ErrCLIUnexpectedArgs.Error())
|
||||
t.Run("Unwrap with nil error", func(t *testing.T) {
|
||||
err := NewUnmarshalError(nil)
|
||||
|
||||
assert.Equal(t, ErrNoError, err.Unwrap())
|
||||
})
|
||||
}
|
||||
|
||||
func TestNewUnmarshalError(t *testing.T) {
|
||||
t.Run("Creates UnmarshalError with correct values", func(t *testing.T) {
|
||||
originalErr := errors.New("test error")
|
||||
err := NewUnmarshalError(originalErr)
|
||||
|
||||
assert.Equal(t, originalErr, err.error)
|
||||
})
|
||||
|
||||
t.Run("Creates UnmarshalError with ErrNoError when nil passed", func(t *testing.T) {
|
||||
err := NewUnmarshalError(nil)
|
||||
|
||||
assert.Equal(t, ErrNoError, err.error)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -242,4 +272,9 @@ func TestErrorImplementsErrorInterface(t *testing.T) {
|
||||
var err error = NewRemoteConfigFileParseError(errors.New("test"))
|
||||
assert.Error(t, err)
|
||||
})
|
||||
|
||||
t.Run("UnmarshalError implements error interface", func(t *testing.T) {
|
||||
var err error = NewUnmarshalError(errors.New("test"))
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user