Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test(provisioner/terraform): use cmp.Diff instead of require.Equal#16449

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

mafredri
Copy link
Member

I would like to swap outrequire.Equal forcmp.Diff in the terraform tests as I find it produces more easy to understand diffs.

Here's an example wherecmp.Diff is clearer, butrequire.Equal performs not-super-terribly. But there are also many cases whererequire.Equal is really hard to understand.

cmp.Diff:

coder@w ~/coder mafredri/test-provisioner-terraform-improve-diff*❯ go test ./provisioner/terraform -run=TestConvertResources -count=1--- FAIL: TestConvertResources (0.00s)    --- FAIL: TestConvertResources/multiple-apps (0.00s)        --- FAIL: TestConvertResources/multiple-apps/Plan (0.02s)            resources_test.go:847:                        Error Trace:    /home/coder/coder/provisioner/terraform/resources_test.go:847                        Error:          unexpected resources                        Test:           TestConvertResources/multiple-apps/Plan                        Messages:       diff (-want +got):                                          []map[string]any{                                                {                                                        "agents": []any{                                                                map[string]any{                                                                        "Auth": map[string]any{"Token": string("")},                                                                        "apps": []any{                                                                                map[string]any{                                        -                                               "display_name": string("app0"),                                        +                                               "display_name": string("app1"),                                                                                        "open_in":      float64(1),                                        -                                               "slug":         string("app0"),                                        +                                               "slug":         string("app1"),                                                                                },                                                                                map[string]any{"display_name": string("app2"), "healthcheck": map[string]any{"interval": float64(5), "threshold": float64(6), "url": string("http://localhost:13337/healthz")}, "open_in": float64(1), "slug": string("app2"), ...},                                                                                map[string]any{                                        -                                               "display_name": string("app4"),                                        +                                               "display_name": string("app3"),                                                                                        "open_in":      float64(1),                                        -                                               "slug":         string("app4"),                                        +                                               "slug":         string("app3"),                                                                                },                                                                        },                                                                        "architecture":               string("amd64"),                                                                        "connection_timeout_seconds": float64(120),                                                                        ... // 4 identical entries                                                                },                                                        },                                                        "name": string("dev"),                                                        "type": string("null_resource"),                                                },                                          }        --- FAIL: TestConvertResources/multiple-apps/Provision (0.02s)            resources_test.go:904:                        Error Trace:    /home/coder/coder/provisioner/terraform/resources_test.go:904                        Error:          unexpected resources                        Test:           TestConvertResources/multiple-apps/Provision                        Messages:       diff (-want +got):                                          []map[string]any{                                                {                                                        "agents": []any{                                                                map[string]any{                                                                        "Auth": map[string]any{"Token": string("")},                                                                        "apps": []any{                                                                                map[string]any{                                        -                                               "display_name": string("app0"),                                        +                                               "display_name": string("app1"),                                                                                        "open_in":      float64(1),                                        -                                               "slug":         string("app0"),                                        +                                               "slug":         string("app1"),                                                                                },                                                                                map[string]any{"display_name": string("app2"), "healthcheck": map[string]any{"interval": float64(5), "threshold": float64(6), "url": string("http://localhost:13337/healthz")}, "open_in": float64(1), "slug": string("app2"), ...},                                                                                map[string]any{                                        -                                               "display_name": string("app4"),                                        +                                               "display_name": string("app3"),                                                                                        "open_in":      float64(1),                                        -                                               "slug":         string("app4"),                                        +                                               "slug":         string("app3"),                                                                                },                                                                        },                                                                        "architecture":               string("amd64"),                                                                        "connection_timeout_seconds": float64(120),                                                                        ... // 4 identical entries                                                                },                                                        },                                                        "name": string("dev"),                                                        "type": string("null_resource"),                                                },                                          }FAILFAIL    github.com/coder/coder/v2/provisioner/terraform 0.043sFAIL

require.Equal:

coder@w ~/coder mafredri/test-provisioner-terraform-improve-diff* 6s❯ go test ./provisioner/terraform -run=TestConvertResources -count=1--- FAIL: TestConvertResources (0.00s)    --- FAIL: TestConvertResources/multiple-apps (0.00s)        --- FAIL: TestConvertResources/multiple-apps/Provision (0.01s)            resources_test.go:900:                        Error Trace:    /home/coder/coder/provisioner/terraform/resources_test.go:900                        Error:          Not equal:                                        expected: []map[string]interface {}{map[string]interface {}{"agents":[]interface {}{map[string]interface {}{"Auth":map[string]interface {}{"Token":""}, "apps":[]interface {}{map[string]interface {}{"display_name":"app0", "open_in":1, "slug":"app0"}, map[string]interface {}{"display_name":"app2", "healthcheck":map[string]interface {}{"interval":5, "threshold":6, "url":"http://localhost:13337/healthz"}, "open_in":1, "slug":"app2", "subdomain":true}, map[string]interface {}{"display_name":"app4", "open_in":1, "slug":"app4"}}, "architecture":"amd64", "connection_timeout_seconds":120, "display_apps":map[string]interface {}{"port_forwarding_helper":true, "ssh_helper":true, "vscode":true, "web_terminal":true}, "name":"dev1", "operating_system":"linux", "resources_monitoring":map[string]interface {}{}}}, "name":"dev", "type":"null_resource"}}                                        actual  : []map[string]interface {}{map[string]interface {}{"agents":[]interface {}{map[string]interface {}{"Auth":map[string]interface {}{"Token":""}, "apps":[]interface {}{map[string]interface {}{"display_name":"app1", "open_in":1, "slug":"app1"}, map[string]interface {}{"display_name":"app2", "healthcheck":map[string]interface {}{"interval":5, "threshold":6, "url":"http://localhost:13337/healthz"}, "open_in":1, "slug":"app2", "subdomain":true}, map[string]interface {}{"display_name":"app3", "open_in":1, "slug":"app3"}}, "architecture":"amd64", "connection_timeout_seconds":120, "display_apps":map[string]interface {}{"port_forwarding_helper":true, "ssh_helper":true, "vscode":true, "web_terminal":true}, "name":"dev1", "operating_system":"linux", "resources_monitoring":map[string]interface {}{}}}, "name":"dev", "type":"null_resource"}}                                        Diff:                                        --- Expected                                        +++ Actual                                        @@ -9,5 +9,5 @@                                              (map[string]interface {}) (len=3) {                                        -      (string) (len=12) "display_name": (string) (len=4) "app0",                                        +      (string) (len=12) "display_name": (string) (len=4) "app1",                                               (string) (len=7) "open_in": (float64) 1,                                        -      (string) (len=4) "slug": (string) (len=4) "app0"                                        +      (string) (len=4) "slug": (string) (len=4) "app1"                                              },                                        @@ -25,5 +25,5 @@                                              (map[string]interface {}) (len=3) {                                        -      (string) (len=12) "display_name": (string) (len=4) "app4",                                        +      (string) (len=12) "display_name": (string) (len=4) "app3",                                               (string) (len=7) "open_in": (float64) 1,                                        -      (string) (len=4) "slug": (string) (len=4) "app4"                                        +      (string) (len=4) "slug": (string) (len=4) "app3"                                              }                        Test:           TestConvertResources/multiple-apps/Provision        --- FAIL: TestConvertResources/multiple-apps/Plan (0.01s)            resources_test.go:845:                        Error Trace:    /home/coder/coder/provisioner/terraform/resources_test.go:845                        Error:          Not equal:                                        expected: []map[string]interface {}{map[string]interface {}{"agents":[]interface {}{map[string]interface {}{"Auth":map[string]interface {}{"Token":""}, "apps":[]interface {}{map[string]interface {}{"display_name":"app0", "open_in":1, "slug":"app0"}, map[string]interface {}{"display_name":"app2", "healthcheck":map[string]interface {}{"interval":5, "threshold":6, "url":"http://localhost:13337/healthz"}, "open_in":1, "slug":"app2", "subdomain":true}, map[string]interface {}{"display_name":"app4", "open_in":1, "slug":"app4"}}, "architecture":"amd64", "connection_timeout_seconds":120, "display_apps":map[string]interface {}{"port_forwarding_helper":true, "ssh_helper":true, "vscode":true, "web_terminal":true}, "name":"dev1", "operating_system":"linux", "resources_monitoring":map[string]interface {}{}}}, "name":"dev", "type":"null_resource"}}                                        actual  : []map[string]interface {}{map[string]interface {}{"agents":[]interface {}{map[string]interface {}{"Auth":map[string]interface {}{"Token":""}, "apps":[]interface {}{map[string]interface {}{"display_name":"app1", "open_in":1, "slug":"app1"}, map[string]interface {}{"display_name":"app2", "healthcheck":map[string]interface {}{"interval":5, "threshold":6, "url":"http://localhost:13337/healthz"}, "open_in":1, "slug":"app2", "subdomain":true}, map[string]interface {}{"display_name":"app3", "open_in":1, "slug":"app3"}}, "architecture":"amd64", "connection_timeout_seconds":120, "display_apps":map[string]interface {}{"port_forwarding_helper":true, "ssh_helper":true, "vscode":true, "web_terminal":true}, "name":"dev1", "operating_system":"linux", "resources_monitoring":map[string]interface {}{}}}, "name":"dev", "type":"null_resource"}}                                        Diff:                                        --- Expected                                        +++ Actual                                        @@ -9,5 +9,5 @@                                              (map[string]interface {}) (len=3) {                                        -      (string) (len=12) "display_name": (string) (len=4) "app0",                                        +      (string) (len=12) "display_name": (string) (len=4) "app1",                                               (string) (len=7) "open_in": (float64) 1,                                                                                                                                     -      (string) (len=4) "slug": (string) (len=4) "app0"                                        +      (string) (len=4) "slug": (string) (len=4) "app1"                                              },                                        @@ -25,5 +25,5 @@                                              (map[string]interface {}) (len=3) {                                        -      (string) (len=12) "display_name": (string) (len=4) "app4",                                        +      (string) (len=12) "display_name": (string) (len=4) "app3",                                               (string) (len=7) "open_in": (float64) 1,                                        -      (string) (len=4) "slug": (string) (len=4) "app4"                                        +      (string) (len=4) "slug": (string) (len=4) "app3"                                              }                        Test:           TestConvertResources/multiple-apps/PlanFAILFAIL    github.com/coder/coder/v2/provisioner/terraform 0.042sFAIL

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

Thatdoes look nicer!

@mafredrimafredrienabled auto-merge (squash)February 5, 2025 14:15
@mafredrimafredri merged commitb3b229c intomainFeb 5, 2025
32 checks passed
@mafredrimafredri deleted the mafredri/test-provisioner-terraform-improve-diff branchFebruary 5, 2025 14:20
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsFeb 5, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@mafredri@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp