Skip to content

chore: unit test to enforce authorized queries match args #11211

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

Merged
merged 7 commits into from
Dec 15, 2023

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented Dec 14, 2023

Closes #11073

The input args could still be incorrect... Added

When running make gen this is an example failure:

generate
--- FAIL: TestCustomQueriesSyncedRowScan (0.00s)
    modelqueries_test.go:82: 
                Error Trace:    /home/steven/go/src/github.com/coder/coder/coderd/database/gentest/modelqueries_test.go:82
                                                        /home/steven/go/src/github.com/coder/coder/coderd/database/gentest/modelqueries_test.go:61
                Error:          Not equal: 
                                expected: []string{"ID", "CreatedAt", "UpdatedAt", "OwnerID", "OrganizationID", "TemplateID", "Deleted", "Name", "AutostartSchedule", "Ttl", "LastUsedAt", "DormantAt", "DeletingAt", "AutomaticUpdates", "TemplateName", "TemplateVersionID", "TemplateVersionName", "Count"}
                                actual  : []string{"ID", "CreatedAt", "UpdatedAt", "OwnerID", "OrganizationID", "Deleted", "Name", "AutostartSchedule", "Ttl", "LastUsedAt", "DormantAt", "DeletingAt", "AutomaticUpdates", "TemplateName", "TemplateVersionID", "TemplateVersionName", "Count"}
                                
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1,2 +1,2 @@
                                -([]string) (len=18) {
                                +([]string) (len=17) {
                                  (string) (len=2) "ID",
                                @@ -6,3 +6,2 @@
                                  (string) (len=14) "OrganizationID",
                                - (string) (len=10) "TemplateID",
                                  (string) (len=7) "Deleted",
                Test:           TestCustomQueriesSyncedRowScan
                Messages:       mismatched args for GetWorkspaces and GetAuthorizedWorkspaces
    modelqueries_test.go:64: The functions "GetTemplates" and "GetAuthorizedTemplates" need to have identical 'rows.Scan()' in their function bodies. Make sure to copy the function body from the autogenerated "GetTemplates" body. Specifically the parameters for 'rows.Scan()'.
FAIL
FAIL    github.com/coder/coder/v2/coderd/database/gentest       0.010s
FAIL

Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

👍 Nice. Green light from me once CI is happy.

@Emyrk Emyrk force-pushed the stevenmasley/authorized_query_check branch from 0f0fe68 to d24c77e Compare December 14, 2023 18:10
@Emyrk
Copy link
Member Author

Emyrk commented Dec 14, 2023

👍 Nice. Green light from me once CI is happy.

CI was failing because main had a migration that changes the columns. So this test failed at make gen, which is exactly what we want.

Just realized this can also help debug if your branch is failing because main moved from under you. Kinda neat

@Emyrk Emyrk enabled auto-merge (squash) December 15, 2023 18:10
@Emyrk Emyrk merged commit 3f6096b into main Dec 15, 2023
@Emyrk Emyrk deleted the stevenmasley/authorized_query_check branch December 15, 2023 20:31
@github-actions github-actions bot locked and limited conversation to collaborators Dec 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

give better error messages when queries in modelqueries.go break
2 participants