Skip to content

Instantly share code, notes, and snippets.

@jehaby
Last active November 27, 2018 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jehaby/0a58675a657cebda8d4c7b2bab9a8e11 to your computer and use it in GitHub Desktop.
Save jehaby/0a58675a657cebda8d4c7b2bab9a8e11 to your computer and use it in GitHub Desktop.
testify Contains
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
type eee struct{}
func (eee) Error() string { return "hohoho" }
func TestOne(t *testing.T) {
e := eee{}
require.Contains(t, e, "ho")
}
func TestTwo(t *testing.T) {
e := eee{}
require.Contains(t, e, "ha")
}
func TestThree(t *testing.T) {
e := eee{}
require.Contains(t, e.Error(), "ho")
}
@jehaby
Copy link
Author

jehaby commented Nov 27, 2018

output:

$ go test contains_test.go 
--- FAIL: TestOne (0.00s)
    require.go:44: 
        	Error Trace:	contains_test.go:15
        	Error:      	"hohoho" could not be applied builtin len()
        	Test:       	TestOne
--- FAIL: TestTwo (0.00s)
    require.go:44: 
        	Error Trace:	contains_test.go:20
        	Error:      	"hohoho" could not be applied builtin len()
        	Test:       	TestTwo
FAIL
FAIL	command-line-arguments	0.004s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment