Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require.Equal panics when using string type alias #646

Closed
kortac opened this issue Aug 8, 2018 · 2 comments
Closed

require.Equal panics when using string type alias #646

kortac opened this issue Aug 8, 2018 · 2 comments

Comments

@kortac
Copy link

kortac commented Aug 8, 2018

I'm trying to compare IDs of package github.com/graph-gophers/graphql-go. These IDs are actually just a type alias for strings:

// ID represents GraphQL's "ID" scalar type. A custom type may be used instead.
type ID string

However if these IDs are not equal, require.Equal panics:

func TestResolver(t *testing.T) {
	require.Equal(t, graphql.ID("2015"), graphql.ID("1915"))
}
=== RUN   TestResolver
--- FAIL: TestResolver (0.00s)
panic: interface conversion: interface {} is graphql.ID, not string [recovered]
	panic: interface conversion: interface {} is graphql.ID, not string

goroutine 148 [running]:
testing.tRunner.func1(0xc4203ac1e0)
	/usr/local/go/src/testing/testing.go:742 +0x567
panic(0x1a60400, 0xc420280440)
	/usr/local/go/src/runtime/panic.go:502 +0x24a
github.com/SpaceHeroGuide/wertungsheft/vendor/github.com/stretchr/testify/assert.diff(0x1a56c80, 0x1c484e0, 0x1a56c80, 0x1c484f0, 0x0, 0x0)
	/Users/matthias/Golang/src/github.com/SpaceHeroGuide/wertungsheft/vendor/github.com/stretchr/testify/assert/assertions.go:1352 +0x4ba
github.com/SpaceHeroGuide/wertungsheft/vendor/github.com/stretchr/testify/assert.Equal(0x44a0188, 0xc4203ac1e0, 0x1a56c80, 0x1c484e0, 0x1a56c80, 0x1c484f0, 0x0, 0x0, 0x0, 0xc4203ac1e0)
	/Users/matthias/Golang/src/github.com/SpaceHeroGuide/wertungsheft/vendor/github.com/stretchr/testify/assert/assertions.go:338 +0x2f8
github.com/SpaceHeroGuide/wertungsheft/vendor/github.com/stretchr/testify/require.Equal(0x1c508e0, 0xc4203ac1e0, 0x1a56c80, 0x1c484e0, 0x1a56c80, 0x1c484f0, 0x0, 0x0, 0x0)
	/Users/matthias/Golang/src/github.com/SpaceHeroGuide/wertungsheft/vendor/github.com/stretchr/testify/require/require.go:157 +0xc0
github.com/SpaceHeroGuide/wertungsheft/vendor/github.com/stretchr/testify/require.(*Assertions).Equal(0xc42036ae68, 0x1a56c80, 0x1c484e0, 0x1a56c80, 0x1c484f0, 0x0, 0x0, 0x0)
	/Users/matthias/Golang/src/github.com/SpaceHeroGuide/wertungsheft/vendor/github.com/stretchr/testify/require/require_forward.go:130 +0xe3
github.com/SpaceHeroGuide/wertungsheft/pkg/api/tournament_test.TestResolver(0xc4203ac1e0)
	/Users/matthias/Golang/src/github.com/SpaceHeroGuide/wertungsheft/pkg/api/tournament/tournament_test.go:90 +0x163
testing.tRunner(0xc4203ac1e0, 0x1b6a7a0)
	/usr/local/go/src/testing/testing.go:777 +0x16e
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:824 +0x565
FAIL	github.com/SpaceHeroGuide/wertungsheft/pkg/api/tournament	2.198s

If you change the IDs so they are equal, the panic does not occur.

@devdinu
Copy link
Contributor

devdinu commented Aug 9, 2018

Duplicate or Same as #644.

@HaraldNordgren
Copy link
Contributor

HaraldNordgren commented Sep 11, 2018

Created a PR here which should solve the problem 😊

#661

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants