Skip to content

Commit

Permalink
cli: getuser command can get Super_priv
Browse files Browse the repository at this point in the history
  • Loading branch information
dbkernel authored and BohuTANG committed Nov 29, 2019
1 parent 8d923a8 commit d2d871a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/model/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ type MysqlUserRPCRequest struct {
}

type MysqlUser struct {
User string
Host string
User string
Host string
SuperPriv string
}

type MysqlUserRPCResponse struct {
Expand Down
6 changes: 4 additions & 2 deletions src/mysql/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,11 @@ func (mogtid *MockGTID) CreateUser(db *sql.DB, user string, passwd string) error
func DefaultGetUser(db *sql.DB) ([]model.MysqlUser, error) {
return []model.MysqlUser{
{User: "user1",
Host: "localhost"},
Host: "localhost",
SuperPriv: "N"},
{User: "root",
Host: "localhost"},
Host: "localhost",
SuperPriv: "Y"},
}, nil
}

Expand Down
4 changes: 2 additions & 2 deletions src/mysql/mysqlbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,17 @@ func (my *MysqlBase) CheckUserExists(db *sql.DB, user string) (bool, error) {

// GetUser used to get the mysql user list
func (my *MysqlBase) GetUser(db *sql.DB) ([]model.MysqlUser, error) {
query := fmt.Sprintf("SELECT User, Host FROM mysql.user")
query := fmt.Sprintf("SELECT User, Host, Super_priv FROM mysql.user")
rows, err := Query(db, query)
if err != nil {
return nil, err
}

var Users = make([]model.MysqlUser, len(rows))

for i, v := range rows {
Users[i].User = v["User"]
Users[i].Host = v["Host"]
Users[i].SuperPriv = v["Super_priv"]
}
return Users, nil
}
Expand Down
13 changes: 8 additions & 5 deletions src/mysql/mysqlbase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,18 @@ func TestGetUser(t *testing.T) {
mysql := NewMysql(conf, log)
mysql.db = db

query := "SELECT User, Host FROM mysql.user"
columns := []string{"User", "Host"}
query := "SELECT User, Host, Super_priv FROM mysql.user"
columns := []string{"User", "Host", "Super_priv"}
want := []model.MysqlUser{
{User: "user1",
Host: "localhost"},
Host: "localhost",
SuperPriv: "N"},
{User: "root",
Host: "localhost"},
Host: "localhost",
SuperPriv: "Y"},
}
mockRows := sqlmock.NewRows(columns).AddRow("user1", "localhost").AddRow("root", "localhost")

mockRows := sqlmock.NewRows(columns).AddRow("user1", "localhost", "N").AddRow("root", "localhost", "Y")
mock.ExpectQuery(query).WillReturnRows(mockRows)

got, err := mysql.GetUser()
Expand Down
6 changes: 4 additions & 2 deletions src/server/rpc_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ func TestServerRPCUser(t *testing.T) {

want1 := []model.MysqlUser{
{User: "user1",
Host: "localhost"},
Host: "localhost",
SuperPriv: "N"},
{User: "root",
Host: "localhost"},
Host: "localhost",
SuperPriv: "Y"},
}
got1 := rsp.Users
assert.Equal(t, want1, got1)
Expand Down

0 comments on commit d2d871a

Please sign in to comment.