Skip to content

Commit

Permalink
Add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Milad Abbasi committed Feb 2, 2021
1 parent da0b2b9 commit ce9a79c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Expand Up @@ -24,7 +24,7 @@ jobs:
run: go build -v ./...

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

- name: Coverage
- name: Codecov
uses: codecov/codecov-action@v1
60 changes: 60 additions & 0 deletions errors_test.go
@@ -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")
}
5 changes: 5 additions & 0 deletions testdata/config.yml
@@ -1,4 +1,9 @@
foo:
&foo
bar: baz

config:
host: golang.org
<<: *foo

custom_key: custom

0 comments on commit ce9a79c

Please sign in to comment.