Skip to content

Commit

Permalink
fix: ci lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zl03jsj committed Sep 22, 2022
1 parent 07bd06c commit 026f7fa
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion auth/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestJwt(t *testing.T) {
var originLimits []*storage.UserRateLimit

if err := json.Unmarshal([]byte(limitStrs), &originLimits); err != nil {
t.Fatal(fmt.Sprintf("initialize origin Ratelimit failed:%s", err.Error()))
t.Fatalf("initialize origin Ratelimit failed:%s", err.Error())
}

var userMiners = map[string][]string{
Expand Down
1 change: 0 additions & 1 deletion integrate_test/token_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//stm: #integration
package integrate

import (
Expand Down
34 changes: 16 additions & 18 deletions storage/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (

type anyTime struct{}

var simulateError = fmt.Errorf("just simulate an error")
var errSimulated = fmt.Errorf("just simulate an error")

func sqlMockExpect(m sqlmock.Sqlmock, prefix string, fail bool) {
m.ExpectBegin()
exe := m.ExpectExec(regexp.QuoteMeta(prefix))
if fail {
exe.WillReturnError(simulateError)
exe.WillReturnError(errSimulated)
m.ExpectRollback()
return
}
Expand All @@ -52,7 +52,6 @@ func TestMysqlStore(t *testing.T) {
if err != nil {
t.Fatal(err)
}

// Token
//stm: @VENUSAUTH_MYSQL_PUT_001
t.Run("mysql put token", wrapper(testMySQLPutToken, mySQLStore, mock))
Expand Down Expand Up @@ -197,10 +196,9 @@ func testMySQLGetToken(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmoc

mock.ExpectQuery(regexp.QuoteMeta(
"SELECT * FROM `token` WHERE token = ? and is_deleted=? LIMIT 1")).
WithArgs(token, core.NotDelete).WillReturnError(simulateError)
WithArgs(token, core.NotDelete).WillReturnError(errSimulated)
_, err = mySQLStore.Get(token)
assert.Equal(t, err, simulateError)

assert.Error(t, err)
}

func testMySQLGetTokenRecord(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmock) {
Expand All @@ -219,9 +217,9 @@ func testMySQLGetTokenRecord(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.

mock.ExpectQuery(regexp.QuoteMeta(
"SELECT * FROM `token` WHERE token = ? LIMIT 1")).
WithArgs(token).WillReturnError(simulateError)
WithArgs(token).WillReturnError(errSimulated)
_, err = mySQLStore.GetTokenRecord(token)
assert.Equal(t, err, simulateError)
assert.Error(t, err)
}

func testMySQLGetTokenByName(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmock) {
Expand Down Expand Up @@ -258,10 +256,10 @@ func testMySQLListTokens(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlm

mock.ExpectQuery(regexp.QuoteMeta(
fmt.Sprintf("SELECT * FROM `token` WHERE is_deleted=? ORDER BY name LIMIT %v OFFSET %v", limit, skip))).
WithArgs(core.NotDelete).WillReturnError(simulateError)
WithArgs(core.NotDelete).WillReturnError(errSimulated)

_, err = mySQLStore.List(skip, limit)
assert.Equal(t, err, simulateError)
assert.Error(t, err)
}

func testMySQLDeleteToken(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmock) {
Expand All @@ -285,7 +283,7 @@ func testMySQLDeleteToken(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sql
// simulate `Has` retuens an error
mock.ExpectQuery(regexp.QuoteMeta(
"SELECT count(*) FROM `token` WHERE token=? and is_deleted=?")).
WithArgs(token, core.NotDelete).WillReturnError(simulateError)
WithArgs(token, core.NotDelete).WillReturnError(errSimulated)
assert.Error(t, mySQLStore.Delete(token))

// `Has` returns a false
Expand All @@ -311,7 +309,7 @@ func testMySQLPutUser(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmock
assert.Nil(t, mySQLStore.PutUser(user))

sqlMockExpect(mock, op, true)
assert.Equal(t, mySQLStore.PutUser(user), simulateError)
assert.Error(t, mySQLStore.PutUser(user))
}

func testMySQLUpdateUser(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmock) {
Expand All @@ -331,7 +329,7 @@ func testMySQLUpdateUser(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlm

sqlMockExpect(mock, op, true)
err = mySQLStore.UpdateUser(newUser)
assert.Equal(t, err, simulateError)
assert.Error(t, err)
}

func testMySQLHasUser(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmock) {
Expand All @@ -344,9 +342,9 @@ func testMySQLHasUser(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmock
assert.Nil(t, err)
assert.True(t, exist)

mock.ExpectQuery(op).WillReturnError(simulateError)
mock.ExpectQuery(op).WillReturnError(errSimulated)
_, err = mySQLStore.HasUser(user)
assert.Equal(t, err, simulateError)
assert.Error(t, err)
}

func testMySQLGetUser(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmock) {
Expand All @@ -364,7 +362,7 @@ func testMySQLGetUser(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmock
assert.Equal(t, userInfo.Name, user)
assert.Equal(t, userInfo.Comment, comment)

mock.ExpectQuery(op).WillReturnError(simulateError)
mock.ExpectQuery(op).WillReturnError(errSimulated)
_, err = mySQLStore.GetUser(user)
assert.Error(t, err)
}
Expand All @@ -383,7 +381,7 @@ func testMySQLGetUserRecord(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.S
assert.Equal(t, userInfo.Name, user)
assert.Equal(t, userInfo.Comment, comment)

mock.ExpectQuery(op).WillReturnError(simulateError)
mock.ExpectQuery(op).WillReturnError(errSimulated)
_, err = mySQLStore.GetUserRecord(user)
assert.Error(t, err)
}
Expand All @@ -399,7 +397,7 @@ func testMySQLListUsers(t *testing.T, mySQLStore *mysqlStore, mock sqlmock.Sqlmo
assert.Nil(t, err)
assert.Equal(t, 2, len(users))

mock.ExpectQuery(op).WillReturnError(simulateError)
mock.ExpectQuery(op).WillReturnError(errSimulated)
_, err = mySQLStore.ListUsers(skip, limit, core.UserStateUndefined)
assert.Error(t, err)

Expand Down
2 changes: 1 addition & 1 deletion storage/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (s *StoreVersion) Bytes() ([]byte, error) {
}

// we are perpose to support limit user requests with `Service`/`Service.API` ferther,
// so we add their declars in `UserRateLimit`
// so we add their declar in `UserRateLimit`
type UserRateLimit struct {
Id string `gorm:"column:id;type:varchar(64);primary_key"`
Name string `gorm:"column:name;type:varchar(50);index:user_service_api_IDX;not null" binding:"required"`
Expand Down
2 changes: 2 additions & 0 deletions storage/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ func testDeleteUser(t *testing.T) {
updated.State = core.UserStateEnabled
updated.Comment = "new comment"
require.NoError(t, theStore.UpdateUser(updated))

res, err = theStore.GetUser(res.Name)
require.NoError(t, err)
require.Equal(t, res.State, updated.State)
require.Equal(t, res.Comment, updated.Comment)
}
Expand Down

0 comments on commit 026f7fa

Please sign in to comment.