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

Bulk convert to using testify/suite for tests #1185

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ashb
Copy link
Contributor

@ashb ashb commented May 8, 2023

This is in some regards a "change for no purpose" but it lets us more
easily add setup or teardown to tests.

The go test compatible test was named after the Go packge
./pkg/workspace becomes TestPkgWorkspaceSuite.

This change was almost entirely automatically applied using
github.com/uber-go/gopatch

Edit: that first t.Errorf -> s.Errorf diff was incorrect. Since removed

The patch file used was this:

@@
@@
 import "github.com/stretchr/testify/assert"

-if err != nil {
-	t.Error(err)
-}
+assert.NoError(t, err)

@@
@@
 import "github.com/stretchr/testify/assert"

-assert.Nil(t, err)
+assert.NoError(t, err)

@@
var foo identifier
@@
-func foo(t *testing.T) {
+func (s *Suite) foo(t *testing.T) {
  ...
 }

@@
var name expression
@@
-t.Run(name, func(t *testing.T) {
+s.Run(name, func() {
  ...
 })

@@
var bar identifier
@@
 import "github.com/stretchr/testify/assert"

- assert.bar(t, ...)
+ s.bar(...)

@@
@@

-if err != nil {
-	t.Fatal(err)
-}
+s.Require().NoError(err)

@@
var foo identifier
@@
-func (s *Suite) foo(t *testing.T) {
+func (s *Suite) foo() {
  ...
 }

@@
var foo identifier
@@
-foo.AssertExpectations(t)
+foo.AssertExpectations(s.T())

# Need to change this one back
@@
@@
-    t.Cleanup(func() { mock.AssertExpectations(s.T()) })
+    t.Cleanup(func() { mock.AssertExpectations(t) })

@@
@@
import testUtil "github.com/astronomer/astro-cli/pkg/testing"

-    testUtil.MockUserInput(t, ...)
+    testUtil.MockUserInput(s.T(), ...)


# Reset the suite test back to taking testing.T
@@
var foo identifier
@@
import (
  "testing"
	"github.com/stretchr/testify/suite"
)

-func (s *Suite) foo() {
+func foo(t *testing.T) {
	  suite.Run(t, new(Suite))
 }

@ashb ashb force-pushed the switch-testify-suites branch 3 times, most recently from fd8c002 to db4bd0e Compare May 8, 2023 21:46
ashb added 2 commits May 8, 2023 22:56
This is in some regards a "change for no purpose" but it lets us more
easily add setup or teardown to tests.

The `go test` compatible test was named after the Go packge
`./pkg/workspace` becomes `TestPkgWorkspaceSuite`.

This change was almost entirely automatically applied using
`github.com/uber-go/gopatch`
@kushalmalani
Copy link
Contributor

@ashb This PR has been in draft state for a very long time? Do you still plan to proceed further?

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

Successfully merging this pull request may close these issues.

None yet

2 participants