Skip to content
Snippets Groups Projects
Verified Commit 72e20bd3 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

bugfix wrong return value of function newUnsupportedReflectKindError

parent 98adb543
No related branches found
No related tags found
No related merge requests found
...@@ -28,7 +28,7 @@ func newPathAlreadyExistsError(path string) PathAlreadyExistsError { ...@@ -28,7 +28,7 @@ func newPathAlreadyExistsError(path string) PathAlreadyExistsError {
return PathAlreadyExistsError(errors.New("files " + path + " already exists")) return PathAlreadyExistsError(errors.New("files " + path + " already exists"))
} }
// PathDoesNotExistError is returned when a files does not exist // PathDoesNotExistError is returned when a files do not exist
type PathDoesNotExistError error type PathDoesNotExistError error
func newPathDoesNotExistError(path string) PathDoesNotExistError { func newPathDoesNotExistError(path string) PathDoesNotExistError {
...@@ -59,7 +59,7 @@ func (s *setting[C]) ResetErrors() *setting[C] { ...@@ -59,7 +59,7 @@ func (s *setting[C]) ResetErrors() *setting[C] {
// At the reflect level, some types are not supported // At the reflect level, some types are not supported
type UnsupportedReflectKindError error type UnsupportedReflectKindError error
func newUnsupportedReflectKindError(t reflect.Type) UnsupportedTypeError { func newUnsupportedReflectKindError(t reflect.Type) UnsupportedReflectKindError {
return UnsupportedReflectKindError(errors.New("type " + t.String() + " is not supported")) return UnsupportedReflectKindError(errors.New("type " + t.String() + " is not supported"))
} }
......
package configuration
import (
"github.com/stretchr/testify/assert"
"reflect"
"testing"
)
func TestResetErrors(t *testing.T) {
defaults := ConfigStruct2{
A: "Hello!",
}
c := New(defaults)
assert.False(t, c.HasError())
c.SetDefaultDirectories()
assert.True(t, c.HasError())
c.ResetErrors()
assert.False(t, c.HasError())
}
func TestNewFlagDoesNotExistError(t *testing.T) {
err := newFlagDoesNotExistError("flag")
_, ok := err.(FlagDoesNotExistError)
assert.True(t, ok)
}
func TestNewPathAlreadyExistsError(t *testing.T) {
err := newPathAlreadyExistsError("flag")
_, ok := err.(PathAlreadyExistsError)
assert.True(t, ok)
}
func TestNewPathDoesNotExistError(t *testing.T) {
err := newPathDoesNotExistError("flag")
_, ok := err.(PathDoesNotExistError)
assert.True(t, ok)
}
func TestNewFormatNotSupportedError(t *testing.T) {
err := newFormatNotSupportedError(Yaml)
_, ok := err.(FormatNotSupportedError)
assert.True(t, ok)
}
func TestNewUnsupportedTypeError(t *testing.T) {
x := reflect.TypeOf("string")
err := newUnsupportedTypeError(x)
_, ok := err.(UnsupportedTypeError)
assert.True(t, ok)
}
func TestNewUnsupportedReflectKindError(t *testing.T) {
x := reflect.TypeOf("string")
err := newUnsupportedReflectKindError(x)
_, ok := err.(UnsupportedReflectKindError)
assert.True(t, ok)
}
func TestNewFlagNotFoundError(t *testing.T) {
err := newFlagNotFoundError("flag")
_, ok := err.(FlagNotFoundError)
assert.True(t, ok)
}
func TestNewMismatchedTypeError(t *testing.T) {
x := reflect.TypeOf("string")
err := newMismatchedTypeError(x, x)
_, ok := err.(MismatchedTypeError)
assert.True(t, ok)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment