Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
Close #8
  • Loading branch information
ilyakaznacheev authored Dec 7, 2019
1 parent e930236 commit 71654cd
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cleanenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cleanenv

import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"os"
Expand All @@ -10,12 +11,25 @@ import (
"time"
)

type testUpdater struct {
Data string `env:"DATA"`
err error
}

func (t *testUpdater) Update() error {
return t.err
}

func TestReadEnvVars(t *testing.T) {
durationFunc := func(s string) time.Duration {
d, _ := time.ParseDuration(s)
return d
}

ta := &testUpdater{
err: errors.New("test"),
}

type Combined struct {
Empty int
Default int `env:"TEST0" env-default:"1"`
Expand Down Expand Up @@ -205,6 +219,20 @@ func TestReadEnvVars(t *testing.T) {
want: &AllTypes{},
wantErr: true,
},

{
name: "wrong config type",
cfg: 42,
want: 42,
wantErr: true,
},

{
name: "updater error",
cfg: ta,
want: ta,
wantErr: true,
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 71654cd

Please sign in to comment.