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
Milad Abbasi
committed
Feb 2, 2021
1 parent
da0b2b9
commit ce9a79c
Showing
3 changed files
with
67 additions
and
2 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,60 @@ | ||
package gonfig | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestInvalidInputError_Error(t *testing.T) { | ||
var i interface{} | ||
var s struct{} | ||
var sp *struct{} | ||
num := 2 | ||
|
||
tests := []struct { | ||
input interface{} | ||
expected string | ||
}{ | ||
{ | ||
input: nil, | ||
expected: "<nil>", | ||
}, | ||
{ | ||
input: i, | ||
expected: "<nil>", | ||
}, | ||
{ | ||
input: s, | ||
expected: "non-pointer type", | ||
}, | ||
{ | ||
input: sp, | ||
expected: "nil pointer", | ||
}, | ||
{ | ||
input: &num, | ||
expected: "non-struct type", | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
ie := InvalidInputError{ | ||
Value: reflect.ValueOf(tc.input), | ||
} | ||
|
||
assert.EqualError(t, &ie, "gonfig: invalid input: "+tc.expected) | ||
} | ||
} | ||
|
||
func TestConfigErrors_Error(t *testing.T) { | ||
ce := ConfigErrors{ | ||
errors.New("first"), | ||
errors.New("second"), | ||
errors.New("third"), | ||
} | ||
|
||
assert.EqualError(t, ce, "gonfig:\n * first\n * second\n * third") | ||
} |
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,4 +1,9 @@ | ||
foo: | ||
&foo | ||
bar: baz | ||
|
||
config: | ||
host: golang.org | ||
<<: *foo | ||
|
||
custom_key: custom |