-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support arrays in JSON, ENV, ARGS * Add cover and maintainability badge * Add some asserts functions * Add tests to increase coverage up to 94% * Add ci for go 1.11
- Loading branch information
Showing
13 changed files
with
464 additions
and
29 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ go: | |
- 1.8 | ||
- 1.9 | ||
- "1.10" | ||
- "1.11" | ||
|
||
script: | ||
- make setup && make test |
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,74 @@ | ||
package goconfig | ||
|
||
import ( | ||
"reflect" | ||
"runtime/debug" | ||
"testing" | ||
) | ||
|
||
// AssertNil checks whether the obtained field is equal to nil, | ||
// failing in other case. | ||
func AssertNil(t *testing.T, obtained interface{}) { | ||
|
||
if nil == obtained { | ||
return | ||
} | ||
|
||
if reflect.ValueOf(obtained).IsNil() { | ||
return | ||
} | ||
|
||
line := GetStackLine(2) | ||
t.Errorf("\nExpected: nil \nObtained:%#v\nat %s\n", obtained, line) | ||
} | ||
|
||
// AssertNotNil checks whether the obtained field is distinct to nil, | ||
// failing in other case. | ||
func AssertNotNil(t *testing.T, obtained interface{}) { | ||
|
||
line := GetStackLine(2) | ||
if nil == obtained { | ||
t.Errorf("\nExpected: not nil \nObtained:%#v\nat %s\n", obtained, line) | ||
return | ||
} | ||
|
||
if reflect.ValueOf(obtained).IsNil() { | ||
t.Errorf("\nExpected: not nil \nObtained:%#v\nat %s\n", obtained, line) | ||
return | ||
} | ||
|
||
} | ||
|
||
// AssertEqual checks whether the obtained and expected fields are equal | ||
// failing in other case. | ||
func AssertEqual(t *testing.T, obtained, expected interface{}) bool { | ||
if reflect.DeepEqual(expected, obtained) { | ||
return true | ||
} | ||
|
||
line := GetStackLine(2) | ||
t.Errorf("\nExpected: %#v\nObtained: %#v\nat %s\n", expected, obtained, line) | ||
|
||
return false | ||
} | ||
|
||
// GetStackLine accesses the stack trace to get some lines | ||
// so they can be showed by the tests in case of error. | ||
func GetStackLine(linesToSkip int) string { | ||
|
||
stack := debug.Stack() | ||
lines := make([]string, 0) | ||
index := 0 | ||
for i := 0; i < len(stack); i++ { | ||
if stack[i] == []byte("\n")[0] { | ||
lines = append(lines, string(stack[index:i-1])) | ||
index = i + 1 | ||
} | ||
} | ||
|
||
if linesToSkip >= len(lines) { | ||
return "" | ||
} | ||
|
||
return lines[linesToSkip] | ||
} |
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
Oops, something went wrong.