Lint rule for using wrapper classes for testify suite.Suite (#2661)
Also fixup some missed instances of `suite.Suite` ---- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [x] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #2373 #### Test Plan - [x] 💪 Manual - [ ] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
3a2203ded5
commit
896a9cfeba
@ -34,6 +34,10 @@ linters-settings:
|
||||
- '\bpath\.(Ext|Base|Dir|Join)'
|
||||
# Don't allow the typo m356 to be used in place of m365.
|
||||
- '[Mm]356'
|
||||
# Don't allow use of testify suite directly. Use one of the wrappers from
|
||||
# tester/suite.go instead. Use an ignore lower down to exclude packages
|
||||
# that result in import cycles if they try to use the wrapper.
|
||||
- 'suite\.Suite(# tests should use one of the Suite wrappers in tester package )?'
|
||||
lll:
|
||||
line-length: 120
|
||||
revive:
|
||||
@ -115,4 +119,22 @@ issues:
|
||||
- gofumpt
|
||||
- misspell
|
||||
- errcheck
|
||||
|
||||
- path: internal/tester/suite.go
|
||||
linters:
|
||||
- forbidigo
|
||||
text: "suite.Suite"
|
||||
# account package creates an import cycle with tester package.
|
||||
- path: pkg/account
|
||||
linters:
|
||||
- forbidigo
|
||||
text: "suite.Suite"
|
||||
# storage package creates an import cycle with tester package.
|
||||
- path: pkg/storage
|
||||
linters:
|
||||
- forbidigo
|
||||
text: "suite.Suite"
|
||||
# Not yet updated. Unclear if it should be updated.
|
||||
- path: pkg/repository/loadtest
|
||||
linters:
|
||||
- forbidigo
|
||||
text: "suite.Suite"
|
||||
|
||||
@ -13,11 +13,11 @@ import (
|
||||
)
|
||||
|
||||
type BetaUnitSuite struct {
|
||||
suite.Suite
|
||||
tester.Suite
|
||||
}
|
||||
|
||||
func TestBetaUnitSuite(t *testing.T) {
|
||||
suite.Run(t, new(BetaUnitSuite))
|
||||
suite.Run(t, &BetaUnitSuite{Suite: tester.NewUnitSuite(t)})
|
||||
}
|
||||
|
||||
func (suite *BetaUnitSuite) TestBetaService_Adapter() {
|
||||
|
||||
@ -1,24 +1,24 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/tester"
|
||||
)
|
||||
|
||||
type UsersUnitSuite struct {
|
||||
suite.Suite
|
||||
tester.Suite
|
||||
}
|
||||
|
||||
func TestUsersUnitSuite(t *testing.T) {
|
||||
suite.Run(t, new(UsersUnitSuite))
|
||||
suite.Run(t, &UsersUnitSuite{Suite: tester.NewUnitSuite(t)})
|
||||
}
|
||||
|
||||
func (suite *UsersUnitSuite) TestValidateUser() {
|
||||
t := suite.T()
|
||||
|
||||
name := "testuser"
|
||||
email := "testuser@foo.com"
|
||||
id := "testID"
|
||||
@ -28,20 +28,20 @@ func (suite *UsersUnitSuite) TestValidateUser() {
|
||||
user.SetId(&id)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
args interface{}
|
||||
want models.Userable
|
||||
wantErr bool
|
||||
name string
|
||||
args interface{}
|
||||
want models.Userable
|
||||
errCheck assert.ErrorAssertionFunc
|
||||
}{
|
||||
{
|
||||
name: "Invalid type",
|
||||
args: string("invalid type"),
|
||||
wantErr: true,
|
||||
name: "Invalid type",
|
||||
args: string("invalid type"),
|
||||
errCheck: assert.Error,
|
||||
},
|
||||
{
|
||||
name: "No ID",
|
||||
args: models.NewUser(),
|
||||
wantErr: true,
|
||||
name: "No ID",
|
||||
args: models.NewUser(),
|
||||
errCheck: assert.Error,
|
||||
},
|
||||
{
|
||||
name: "No user principal name",
|
||||
@ -50,24 +50,23 @@ func (suite *UsersUnitSuite) TestValidateUser() {
|
||||
u.SetId(&id)
|
||||
return u
|
||||
}(),
|
||||
wantErr: true,
|
||||
errCheck: assert.Error,
|
||||
},
|
||||
{
|
||||
name: "Valid User",
|
||||
args: user,
|
||||
want: user,
|
||||
name: "Valid User",
|
||||
args: user,
|
||||
want: user,
|
||||
errCheck: assert.NoError,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
suite.Run(tt.name, func() {
|
||||
t := suite.T()
|
||||
|
||||
got, err := validateUser(tt.args)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("parseUser() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("parseUser() = %v, want %v", got, tt.want)
|
||||
}
|
||||
tt.errCheck(t, err)
|
||||
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user