github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/pkg/testutil/helpers.go (about) 1 package testutil 2 3 import ( 4 "strings" 5 "unicode" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 // ErrorContains checks that the error is not nil, and contains the expected 12 // substring. 13 func ErrorContains(t require.TestingT, err error, expectedError string) { 14 require.Error(t, err) 15 assert.Contains(t, err.Error(), expectedError) 16 } 17 18 // EqualNormalizedString compare the actual value to the expected value after applying the specified 19 // transform function. It fails the test if these two transformed string are not equal. 20 // For example `EqualNormalizedString(t, RemoveSpace, "foo\n", "foo")` wouldn't fail the test as 21 // spaces (and thus '\n') are removed before comparing the string. 22 func EqualNormalizedString(t require.TestingT, transformFun func(rune) rune, actual, expected string) { 23 require.Equal(t, strings.Map(transformFun, expected), strings.Map(transformFun, actual)) 24 } 25 26 // RemoveSpace returns -1 if the specified runes is considered as a space (unicode) 27 // and the rune itself otherwise. 28 func RemoveSpace(r rune) rune { 29 if unicode.IsSpace(r) { 30 return -1 31 } 32 return r 33 }