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

mock update with one more paras #270

Open
qinghai5060 opened this issue Sep 27, 2021 · 2 comments
Open

mock update with one more paras #270

qinghai5060 opened this issue Sep 27, 2021 · 2 comments

Comments

@qinghai5060
Copy link

what happened:
when I want to test

_, err := o.QueryTable(Quota{}).Filter("project", project).Update(orm.Params{
		"used":      used,
		"update_at": time.Now().UTC(),
	})

expected sql I tested with UPDATE "quota" SET "used" = $1, "update_at" = $2 WHERE "id" ..., It sometimes happen that the actual is "UPDATE "quota" SET "update_at" = $1, "used" = $2 WHERE "id"", and error occures like:
[UPDATE "quota" SET "update_at" = $1, "used" = $2 WHERE "id" IN ( SELECT T0."id" FROM"quota" T0 WHERE T0."project" = $3 AND T0."type" = $4 )] - 2021-09-27 02:50:17.460540895 +0000 UTC, 11, project001, key - call to ExecQuery 'UPDATE "quota" SET "update_at" = $1, "used" = $2 WHERE "id" IN ( SELECT T0."id" FROM "quota" T0 WHERE T0."project" = $3 AND T0."type" = $4 )' with args [{Name: Ordinal:1 Value:2021-09-27 02:50:17.460540895 +0000 UTC} {Name: Ordinal:2 Value:11} {Name: Ordinal:3 Value:project001} {Name: Ordinal:4 Value:key}] was not expected
I use beego orm lib and orm.Params is a map. For that reason, it is not sorted. Is there any way to solve this?

@Strang
Copy link

Strang commented Apr 26, 2022

Same issue for me, hope to provide some function like:

mock.ExpectExec(regexp.QuoteMeta("UPDATE `quota`")).
    WithSets(map[string]driver.Value{
        "used": 1,
        "update_at": time.Now(),
    })

@Strang
Copy link

Strang commented Apr 28, 2022

I write some code to solve this problem, but I think this code is too tricky to open a MR. Take your own responsibility to use it. If someone has some better idea, plz let me know. :)

Strang@f633abc

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