Apisix-dashboard: feat: use gomega match assertion

Created on 24 Mar 2021  Â·  13Comments  Â·  Source: apache/apisix-dashboard

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/ginkgo_dsl.go:229 +0x218
github.com/onsi/ginkgo.RunSpecs(0x882660, 0xc000001c80, 0x7fa20e, 0xb, 0x6c38b874bdbe8)
        /root/go/pkg/mod/github.com/onsi/[email protected]/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?

backend

Most helpful comment

@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.

All 13 comments

cc @nic-chen @gxthrj @starsz @tokers @juzhiyuan @imjoey

+1
looks great

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

@Jaycean
+1 Gomega

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

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

+1 gomega

+1 Gomega

+1 Gomega

ok fine, anyone would like to take this issue?

ok fine, anyone would like to take this issue?

I will finish it when I have time.

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

@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.

Was this page helpful?
0 / 5 - 0 ratings