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

struggling with mock_catcher: check query and long queries with spaces #18

Open
lauraeci opened this issue Jun 26, 2019 · 1 comment
Open

Comments

@lauraeci
Copy link

Great library. Works wonderfully, except when I am trying to match long multiline queries. copied the query recommended by the

2019/06/26 11:29:07 mock_catcher: check query:  
		SELECT c.week, c.count FROM (
			SELECT date_trunc('week', scheduled_at) week, count(*)
			FROM w
			WHERE id=abf10e8d-5607-430e-acd0-f6bd6a201631
			AND scheduled_at <> 0001-01-01 00:00:00 +0000 UTC
			AND is_optional IS NOT true
			AND type <> rest
			GROUP BY week
			ORDER BY week) s
		JOIN
			(
			SELECT date_trunc('week', completed_at) week, count(*)
			FROM w
			WHERE id=abf10e8d-5607-430e-acd0-f6bd6a201631
			AND completed_at <> 0001-01-01 00:00:00 +0000 UTC
			AND is_optional IS NOT true
			AND type <> rest
			GROUP BY week
			ORDER BY week
			) completed
		ON s.week=c.week
		WHERE c.count>=s.count

Struggling to insert the query into my test and have it match. Returns [0 rows affected or returned ]

It seems very sensitive to spacing? Am I not copying the spaces properly? Is it possible to make it ignore spacing/tabs?

Any advice would be very appreciated. Thank you.

@buildscientist
Copy link

@lauraeci Have you tried using a multi-line string?

The nice thing about a multi-line string in GoLang is that you don't need to escape characters like single/double quotes.

With Go-Mocket that could be something like:

sqlJoin := `SELECT c.week, c.count FROM (
			SELECT date_trunc('week', scheduled_at) week, count(*)
			FROM w
			WHERE id=abf10e8d-5607-430e-acd0-f6bd6a201631
			AND scheduled_at <> 0001-01-01 00:00:00 +0000 UTC
			AND is_optional IS NOT true
			AND type <> rest
			GROUP BY week
			ORDER BY week) s
		JOIN
			(
			SELECT date_trunc('week', completed_at) week, count(*)
			FROM w
			WHERE id=abf10e8d-5607-430e-acd0-f6bd6a201631
			AND completed_at <> 0001-01-01 00:00:00 +0000 UTC
			AND is_optional IS NOT true
			AND type <> rest
			GROUP BY week
			ORDER BY week
			) completed
		ON s.week=c.week
		WHERE c.count>=s.count`
dbReply := []map[string]interface{}{{"week":"35","count":"999"}}
go_mocket.Catcher.NewMock().WithQuery(sqlJoin).WithReply(dbReply)

Here's another guide on String formatting that I've found helpful - How to format strings in Go

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

2 participants