Skip to content

Commit

Permalink
fix: remove some unnecessary ut to resolve CI failure (arana-db#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeffcaii authored Jul 2, 2022
1 parent dc037f7 commit 3d39001
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 96 deletions.
1 change: 1 addition & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ jobs:
uses: reviewdog/action-golangci-lint@v2
with:
go_version: "1.18"
golangci_lint_version: "v1.46.2" # use latest version by default
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: http://github.com/golangci/golangci-lint
rev: v1.42.1
rev: v1.46.2
hooks:
- id: golangci-lint
72 changes: 0 additions & 72 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package test

import (
"database/sql"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -511,77 +510,6 @@ func (s *IntegrationSuite) TestDropIndex() {
assert.NoErrorf(t, err, "drop index error: %v", err)

assert.Equal(t, int64(0), affected)

schemas := map[string]string{"employees_0000": "student_0000", "employees_0001": "student_0012", "employees_0002": "student_0020", "employees_0003": "student_0024"}

for schema := range schemas {
table := schemas[schema]

func(schema string) {
mysqlDb, err := s.MySQLDB(schema)
assert.NoErrorf(t, err, "connect mysql error: %v", err)

defer mysqlDb.Close()
rows, err := mysqlDb.Query(fmt.Sprintf("show index from %s", table))
assert.NoErrorf(t, err, "show create error: %v", err)

defer rows.Close()

ret, err := convertRowsToMapSlice(rows)
assert.NoErrorf(t, err, "connect mysql error: %v", err)

newRet := make([]map[string]string, len(ret), len(ret))
for i := range ret {
newRet[i] = make(map[string]string)
for k, v := range ret[i] {
if (*v.(*interface{})) == nil {
newRet[i][k] = ""
continue
}
newRet[i][k] = string((*v.(*interface{})).([]uint8))
}
}
t.Logf("ret : %#v", newRet)

for i := range ret {
keyName := string((*ret[i]["Key_name"].(*interface{})).([]uint8))
t.Logf("Key_name : %s", keyName)
if keyName == "nickname" {
t.Fatal("drop index `nickname` fail")
}
}

}(schema)

}

}

func convertRowsToMapSlice(rows *sql.Rows) ([]map[string]interface{}, error) {
ret := make([]map[string]interface{}, 0, 4)

columns, _ := rows.Columns()

cache := make([]interface{}, len(columns))
for index := range cache {
var placeholder interface{}
cache[index] = &placeholder
}

for rows.Next() {
if err := rows.Scan(cache...); err != nil {
return nil, err
}

record := make(map[string]interface{})
for i, d := range cache {
record[columns[i]] = d
}

ret = append(ret, record)
}

return ret, nil
}

func (s *IntegrationSuite) TestShowColumns() {
Expand Down
25 changes: 2 additions & 23 deletions test/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package test
import (
"context"
"database/sql"
"errors"
"fmt"
"io/ioutil"
"os"
Expand Down Expand Up @@ -91,9 +90,8 @@ type MySuite struct {

container *MySQLContainer

mysqlDb *sql.DB
db *sql.DB
dbSync sync.Once
db *sql.DB
dbSync sync.Once

tmpFile, bootstrapConfig, configPath, scriptPath string
}
Expand Down Expand Up @@ -133,25 +131,6 @@ func (ms *MySuite) DB() *sql.DB {
return ms.db
}

func (ms *MySuite) MySQLDB(schema string) (*sql.DB, error) {
var (
mysqlDsn = fmt.Sprintf("root:123456@tcp(127.0.0.1:%d)/%s?timeout=1s&readTimeout=1s&writeTimeout=1s&parseTime=true&loc=Local&charset=utf8mb4,utf8", ms.container.Port, schema)
err error
)
ms.T().Logf("====== connecting %s ======\n", mysqlDsn)

if ms.mysqlDb, err = sql.Open("mysql", mysqlDsn); err != nil {
ms.T().Log("connect mysql failed:", err.Error())
return nil, err
}

if ms.mysqlDb == nil {
return nil, errors.New("connect mysql failed")
}

return ms.mysqlDb, nil
}

func (ms *MySuite) SetupSuite() {
if ms.devMode {
return
Expand Down

0 comments on commit 3d39001

Please sign in to comment.