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

feat: use gomega match assertion #1664

Closed
Jaycean opened this issue Mar 24, 2021 · 13 comments · Fixed by #1678
Closed

feat: use gomega match assertion #1664

Jaycean opened this issue Mar 24, 2021 · 13 comments · Fixed by #1678
Assignees
Labels

Comments

@Jaycean
Copy link
Member

Jaycean commented Mar 24, 2021

Feature request

Please describe your feature

  • use gomega match assertion.

Describe the solution you'd like

  • At present, the assertions used in E2E test are directly matched by go assert, so if there is an error, it is not friendly to the error message prompt, so I want to use gomega to match the assertions.

  • Gomega is a matcher/assertion library. It is best paired with the Ginkgo BDD test framework, but can be adapted for use in other contexts too.

  • Gomega Doc

For example

  • When we use this function to read a file ioutil.ReadFile

  • Error tips for using go assert


goroutine 6 [running]:
testing.tRunner.func1.2(0x77ed40, 0x87bf70)
        /usr/local/go/src/testing/testing.go:1144 +0x332
testing.tRunner.func1(0xc000001c80)
        /usr/local/go/src/testing/testing.go:1147 +0x4b6
panic(0x77ed40, 0x87bf70)
        /usr/local/go/src/runtime/panic.go:965 +0x1b9
github.com/onsi/ginkgo.Fail(0xc0000a4b00, 0x15b, 0xc0001a4c98, 0x1, 0x1)
        /root/go/pkg/mod/github.com/onsi/ginkgo@v1.14.2/ginkgo_dsl.go:270 +0xc8
github.com/onsi/ginkgo/internal/testingtproxy.(*ginkgoTestingTProxy).Errorf(0xc0001afd00, 0x7f751e, 0x3, 0xc00020e160, 0x1, 0x1)
        /root/go/pkg/mod/github.com/onsi/ginkgo@v1.14.2/internal/testingtproxy/testing_t_proxy.go:42 +0xc2
github.com/stretchr/testify/assert.Fail(0x7f46dab574b8, 0xc0001afd00, 0xc0001ee720, 0x5a, 0x0, 0x0, 0x0, 0x7df0a0)
        /root/go/pkg/mod/github.com/stretchr/testify@v1.4.0/assert/assertions.go:261 +0x2fb
github.com/stretchr/testify/assert.Nil(0x7f46dab574b8, 0xc0001afd00, 0x79d460, 0xc0001c52f0, 0x0, 0x0, 0x0, 0x8e0ddd)
        /root/go/pkg/mod/github.com/stretchr/testify@v1.4.0/assert/assertions.go:497 +0x12f
github.com/apisix/manager-api/test/e2enew/route.glob..func4()
        /root/apisix-dashboard/api/test/e2enew/route/route_with_plugin_orchestration_test.go:33 +0x125
github.com/onsi/ginkgo/internal/suite.(*Suite).PushContainerNode(0xc0000d4070, 0x8034cf, 0x1f, 0x820db0, 0x0, 0x8e0e18, 0x54, 0x1e, 0xc000114280, 0x95)
        /root/go/pkg/mod/github.com/onsi/ginkgo@v1.14.2/internal/suite/suite.go:181 +0x323
github.com/onsi/ginkgo/internal/suite.(*Suite).Run(0xc0000d4070, 0x7f46dab57470, 0xc000001c80, 0x7fa20e, 0xb, 0xc000172640, 0x1, 0x1, 0x888438, 0xc0000128c0, ...)
        /root/go/pkg/mod/github.com/onsi/ginkgo@v1.14.2/internal/suite/suite.go:70 +0x15b
github.com/onsi/ginkgo.RunSpecsWithCustomReporters(0x882660, 0xc000001c80, 0x7fa20e, 0xb, 0xc000034728, 0x1, 0x1, 0x0)
        /root/go/pkg/mod/github.com/onsi/ginkgo@v1.14.2/ginkgo_dsl.go:229 +0x218
github.com/onsi/ginkgo.RunSpecs(0x882660, 0xc000001c80, 0x7fa20e, 0xb, 0x6c38b874bdbe8)
        /root/go/pkg/mod/github.com/onsi/ginkgo@v1.14.2/ginkgo_dsl.go:210 +0x168
github.com/apisix/manager-api/test/e2enew/route.TestRoute(0xc000001c80)
        /root/apisix-dashboard/api/test/e2enew/route/route_suite_test.go:29 +0x4c
testing.tRunner(0xc000001c80, 0x820c68)
        /usr/local/go/src/testing/testing.go:1194 +0xef
created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:1239 +0x2b3

Ginkgo ran 1 suite in 4.629374607s
Test Suite Failed
  • Error tips for using gomega
Running Suite: route suite
==========================
Random Seed: 1616555228
Will run 115 of 115 specs

••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
------------------------------
• Failure [0.000 seconds]
route with plugin orchestration
/root/apisix-dashboard/api/test/e2enew/route/route_with_plugin_orchestration_test.go:30
  panics if readfile error [It]
  /root/apisix-dashboard/api/test/e2enew/route/route_with_plugin_orchestration_test.go:32

  Expected
      <*fs.PathError | 0xc0001f35f0>: {
          Op: "open",
          Path: "../testdata/invalid-dag-conf.json",
          Err: 0x2,
      }
  to be nil

  /root/apisix-dashboard/api/test/e2enew/route/route_with_plugin_orchestration_test.go:33
------------------------------
• Failure [0.000 seconds]
route with plugin orchestration
/root/apisix-dashboard/api/test/e2enew/route/route_with_plugin_orchestration_test.go:30
  panics if readfile error [It]
  /root/apisix-dashboard/api/test/e2enew/route/route_with_plugin_orchestration_test.go:39

  Expected
      <*fs.PathError | 0xc0001f35f0>: {
          Op: "open",
          Path: "../testdata/invalid-dag-conf.json",
          Err: 0x2,
      }
  to be nil

  /root/apisix-dashboard/api/test/e2enew/route/route_with_plugin_orchestration_test.go:40
------------------------------
•••••••••••••••••••••••••••••••••••••••

Summarizing 2 Failures:

[Fail] route with plugin orchestration [It] panics if readfile error 
/root/apisix-dashboard/api/test/e2enew/route/route_with_plugin_orchestration_test.go:33

[Fail] route with plugin orchestration [It] panics if readfile error 
/root/apisix-dashboard/api/test/e2enew/route/route_with_plugin_orchestration_test.go:40

Ran 115 of 115 Specs in 24.415 seconds
FAIL! -- 113 Passed | 2 Failed | 0 Pending | 0 Skipped
--- FAIL: TestRoute (24.43s)
FAIL

Ginkgo ran 1 suite in 26.455527814s
Test Suite Failed

Do you have any better suggestions?

@Jaycean
Copy link
Member Author

Jaycean commented Mar 24, 2021

@Jaycean Jaycean self-assigned this Mar 24, 2021
@nic-chen
Copy link
Member

+1
looks great

@imjoey
Copy link
Member

imjoey commented Mar 24, 2021

@Jaycean
+1 for me. Gomega is a much better choice. Looking forward to this awesome improvements. Thanks.

@gxthrj
Copy link
Contributor

gxthrj commented Mar 24, 2021

@Jaycean
+1 Gomega

@juzhiyuan
Copy link
Member

Not sure 🤔 I'm not familiar with Go currently.

@tokers
Copy link
Contributor

tokers commented Mar 25, 2021

It seems the output is more friendly, we mat try it.

@bisakhmondal
Copy link
Member

+1 gomega

@batman-ezio
Copy link
Contributor

+1 Gomega

@starsz
Copy link
Contributor

starsz commented Mar 25, 2021

+1 Gomega

@juzhiyuan
Copy link
Member

ok fine, anyone would like to take this issue?

@Jaycean
Copy link
Member Author

Jaycean commented Mar 26, 2021

ok fine, anyone would like to take this issue?

I will finish it when I have time.

@bisakhmondal
Copy link
Member

@Jaycean feel free to ask me if I could be of any help :)
I'd be happy to write some.

@Jaycean
Copy link
Member Author

Jaycean commented Mar 26, 2021

@Jaycean feel free to ask me if I could be of any help :)
I'd be happy to write some.

Thank you very much. Let me finish the issue. If you have time, you can help to finish the issue: #1500 . There are still many E2E tests to rewrite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants