Skip to content

Commit ce9a79c

Browse files
author
Milad Abbasi
committed
Add more test cases
1 parent da0b2b9 commit ce9a79c

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
run: go build -v ./...
2525

2626
- name: Test
27-
run: go test -race -cover -coverprofile="coverage.txt" -covermode=atomic ./...
27+
run: go test -race -cover -coverprofile="coverage.out" -covermode=atomic ./...
2828

29-
- name: Coverage
29+
- name: Codecov
3030
uses: codecov/codecov-action@v1

errors_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package gonfig
2+
3+
import (
4+
"errors"
5+
"reflect"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestInvalidInputError_Error(t *testing.T) {
12+
var i interface{}
13+
var s struct{}
14+
var sp *struct{}
15+
num := 2
16+
17+
tests := []struct {
18+
input interface{}
19+
expected string
20+
}{
21+
{
22+
input: nil,
23+
expected: "<nil>",
24+
},
25+
{
26+
input: i,
27+
expected: "<nil>",
28+
},
29+
{
30+
input: s,
31+
expected: "non-pointer type",
32+
},
33+
{
34+
input: sp,
35+
expected: "nil pointer",
36+
},
37+
{
38+
input: &num,
39+
expected: "non-struct type",
40+
},
41+
}
42+
43+
for _, tc := range tests {
44+
ie := InvalidInputError{
45+
Value: reflect.ValueOf(tc.input),
46+
}
47+
48+
assert.EqualError(t, &ie, "gonfig: invalid input: "+tc.expected)
49+
}
50+
}
51+
52+
func TestConfigErrors_Error(t *testing.T) {
53+
ce := ConfigErrors{
54+
errors.New("first"),
55+
errors.New("second"),
56+
errors.New("third"),
57+
}
58+
59+
assert.EqualError(t, ce, "gonfig:\n * first\n * second\n * third")
60+
}

testdata/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
foo:
2+
&foo
3+
bar: baz
4+
15
config:
26
host: golang.org
7+
<<: *foo
38

49
custom_key: custom

0 commit comments

Comments
 (0)