From ce9a79cbfd831167bc11096225ed10ffca7ad0b1 Mon Sep 17 00:00:00 2001 From: Milad Abbasi Date: Tue, 2 Feb 2021 12:04:59 +0330 Subject: [PATCH] Add more test cases --- .github/workflows/build.yml | 4 +-- errors_test.go | 60 +++++++++++++++++++++++++++++++++++++ testdata/config.yml | 5 ++++ 3 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 errors_test.go diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b91948a..204d8a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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 diff --git a/errors_test.go b/errors_test.go new file mode 100644 index 0000000..8ded33b --- /dev/null +++ b/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: "", + }, + { + input: i, + expected: "", + }, + { + 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") +} diff --git a/testdata/config.yml b/testdata/config.yml index e01786d..367ebee 100644 --- a/testdata/config.yml +++ b/testdata/config.yml @@ -1,4 +1,9 @@ +foo: + &foo + bar: baz + config: host: golang.org + <<: *foo custom_key: custom