-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from DeanPDX/additional-coverage
Add additional test coverage
- Loading branch information
Showing
3 changed files
with
84 additions
and
1 deletion.
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
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 dotconfig | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestErrorsReturnsErr(t *testing.T) { | ||
// Make sure calling Errors on an error just returns that in collection | ||
err := errors.New("test error") | ||
errs := Errors(err) | ||
if len(errs) != 1 { | ||
t.Fatalf("Expected 1 error. Got %v", len(errs)) | ||
} | ||
} | ||
|
||
func TestErrorsReturnsNil(t *testing.T) { | ||
// Make sure calling Errors on an error just returns that in collection | ||
errs := Errors(nil) | ||
if errs != nil { | ||
t.Fatal("Expected nil slice") | ||
} | ||
} | ||
|
||
type empty struct{} | ||
|
||
type required struct { | ||
MyInt int `env:"MY_INT,required"` | ||
} | ||
|
||
type doubleRequired struct { | ||
MyInt int `env:"MY_INT,required"` | ||
MySecond int `env:"MY_SECOND, required"` | ||
} | ||
|
||
func TestErrorsStringer(t *testing.T) { | ||
// Make sure calling Errors on an error just returns that in collection | ||
_, err := FromReader[empty](strings.NewReader("")) | ||
if err != nil { | ||
t.Fatal("Expected nil slice") | ||
} | ||
// Single error should return in common error format | ||
_, err = FromReader[required](strings.NewReader("")) | ||
want := "key not present in ENV: MY_INT" | ||
if err.Error() != want { | ||
t.Fatalf("Expected %v. Got %v.", want, err.Error()) | ||
} | ||
_, err = FromReader[doubleRequired](strings.NewReader("")) | ||
want = `multiple errors: | ||
- key not present in ENV: MY_INT | ||
- key not present in ENV: MY_SECOND` | ||
if err.Error() != want { | ||
t.Fatalf("Expected %v. Got %v.", want, err.Error()) | ||
} | ||
errs := joinError{} | ||
if errs.Error() != "" { | ||
t.Fatalf("Expected empty string. Got: %v", errs.Error()) | ||
} | ||
} |