1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add some unit tests to the node and swarm cli code

Start work on adding unit tests to our cli code in order to have to
write less costly integration test.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2016-12-25 22:23:35 +01:00
parent d4791c7b64
commit f151c297eb
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3
60 changed files with 2512 additions and 147 deletions

View file

@ -7,6 +7,7 @@ import (
"reflect"
"runtime"
"strings"
"unicode"
"github.com/davecgh/go-spew/spew"
)
@ -25,6 +26,25 @@ func Equal(t TestingT, actual, expected interface{}) {
}
}
// EqualNormalizedString compare the actual value to the expected value after applying the specified
// transform function. It fails the test if these two transformed string are not equal.
// For example `EqualNormalizedString(t, RemoveSpace, "foo\n", "foo")` wouldn't fail the test as
// spaces (and thus '\n') are removed before comparing the string.
func EqualNormalizedString(t TestingT, transformFun func(rune) rune, actual, expected string) {
if strings.Map(transformFun, actual) != strings.Map(transformFun, expected) {
fatal(t, "Expected '%v' got '%v'", expected, expected, actual, actual)
}
}
// RemoveSpace returns -1 if the specified runes is considered as a space (unicode)
// and the rune itself otherwise.
func RemoveSpace(r rune) rune {
if unicode.IsSpace(r) {
return -1
}
return r
}
//EqualStringSlice compares two slices and fails the test if they do not contain
// the same items.
func EqualStringSlice(t TestingT, actual, expected []string) {