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

Fix "matches" handling of non-string types #90

Merged
merged 1 commit into from
May 18, 2022

Conversation

wigbam
Copy link
Contributor

@wigbam wigbam commented Aug 28, 2021

This should fix handling of non-string fields when using matches. See amended test for example. Before the fix matches would fail on non-string fields with the following error:

=== RUN   TestStub/find_nested_stub_matches_regex_map
    --- FAIL: TestStub/find_nested_stub_matches_regex_map (0.00s)
panic: interface conversion: interface {} is float64, not string [recovered]
	panic: interface conversion: interface {} is float64, not string

goroutine 34 [running]:
testing.tRunner.func1.2({0x11cb960, 0xc00013ddd0})
	/usr/local/Cellar/go/1.17/libexec/src/testing/testing.go:1209 +0x24e
testing.tRunner.func1()
	/usr/local/Cellar/go/1.17/libexec/src/testing/testing.go:1212 +0x218
panic({0x11cb960, 0xc00013ddd0})
	/usr/local/Cellar/go/1.17/libexec/src/runtime/panic.go:1038 +0x215
github.com/tokopedia/gripmock/stub.regexMatch({0x11bdb60, 0xc0000a7a80}, {0x11bdb60, 0xc0000a7b58})
	/Users/wigbam/workspace/intellij/opensource/gripmock/stub/storage.go:174 +0x167
github.com/tokopedia/gripmock/stub.find({0x11bdb60, 0xc0000a7a80}, {0x11bdb60, 0xc0000a7b58}, 0x68, 0x0, 0x12105e0)
	/Users/wigbam/workspace/intellij/opensource/gripmock/stub/storage.go:261 +0x1de
github.com/tokopedia/gripmock/stub.find({0x11c96c0, 0xc00013da10}, {0x11c96c0, 0xc00013dce0}, 0x1, 0x0, 0x12105e0)
	/Users/wigbam/workspace/intellij/opensource/gripmock/stub/storage.go:255 +0x265
github.com/tokopedia/gripmock/stub.find({0x11c96c0, 0xc00013d9e0}, {0x11c96c0, 0xc00013dcb0}, 0x1, 0x0, 0x12105e0)
	/Users/wigbam/workspace/intellij/opensource/gripmock/stub/storage.go:255 +0x265
github.com/tokopedia/gripmock/stub.find({0x11c96c0, 0xc00013d9b0}, {0x11c96c0, 0xc00013dc80}, 0x1, 0x0, 0x12105e0)
	/Users/wigbam/workspace/intellij/opensource/gripmock/stub/storage.go:255 +0x265
github.com/tokopedia/gripmock/stub.matches(...)
	/Users/wigbam/workspace/intellij/opensource/gripmock/stub/storage.go:193
github.com/tokopedia/gripmock/stub.findStub(0xc00013dc20)
	/Users/wigbam/workspace/intellij/opensource/gripmock/stub/storage.go:89 +0x813
github.com/tokopedia/gripmock/stub.handleFindStub({0x1245050, 0xc0000ed200}, 0xc000128e00)
	/Users/wigbam/workspace/intellij/opensource/gripmock/stub/stub.go:151 +0x10e
github.com/tokopedia/gripmock/stub.TestStub.func18(0x0)
	/Users/wigbam/workspace/intellij/opensource/gripmock/stub/stub_test.go:358 +0xdb
testing.tRunner(0xc000164000, 0xc00014a9a0)
	/usr/local/Cellar/go/1.17/libexec/src/testing/testing.go:1259 +0x102
created by testing.(*T).Run
	/usr/local/Cellar/go/1.17/libexec/src/testing/testing.go:1306 +0x35a

This is my first ever attempt at Golang, so amend as you see fit 😄

@wigbam wigbam changed the title Fix "matches" handling for non-string types Fix "matches" handling of non-string types Aug 28, 2021
@mgerasimchuk
Copy link

@jekiapp please look at this))

Also faced with this problem((

Comment on lines +170 to +171
var expectedStr, expectedStringOk = expect.(string)
var actualStr, actualStringOk = actual.(string)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var expectedStr, expectedStringOk = expect.(string)
var actualStr, actualStringOk = actual.(string)
expectedStr, expectedStringOk := expect.(string)
actualStr, actualStringOk = actual.(string)

@jekiapp jekiapp merged commit 885ab10 into tokopedia:master May 18, 2022
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

Successfully merging this pull request may close these issues.

4 participants