diff --git a/mysql/const.go b/mysql/const.go index 85badda9c..1d80e1664 100644 --- a/mysql/const.go +++ b/mysql/const.go @@ -362,7 +362,7 @@ var Col2PrivType = map[string]PrivilegeType{ } // AllGlobalPrivs is all the privileges in global scope. -var AllGlobalPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, ProcessPriv, GrantPriv, ReferencesPriv, AlterPriv, ShowDBPriv, SuperPriv, ExecutePriv, IndexPriv, CreateUserPriv, TriggerPriv, CreateViewPriv, ShowViewPriv, CreateRolePriv, DropRolePriv} +var AllGlobalPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, ProcessPriv, ReferencesPriv, AlterPriv, ShowDBPriv, SuperPriv, ExecutePriv, IndexPriv, CreateUserPriv, TriggerPriv, CreateViewPriv, ShowViewPriv, CreateRolePriv, DropRolePriv} // Priv2Str is the map for privilege to string. var Priv2Str = map[PrivilegeType]string{ @@ -423,10 +423,10 @@ var SetStr2Priv = map[string]PrivilegeType{ } // AllDBPrivs is all the privileges in database scope. -var AllDBPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, GrantPriv, AlterPriv, ExecutePriv, IndexPriv, CreateViewPriv, ShowViewPriv} +var AllDBPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, AlterPriv, ExecutePriv, IndexPriv, CreateViewPriv, ShowViewPriv} // AllTablePrivs is all the privileges in table scope. -var AllTablePrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, GrantPriv, AlterPriv, IndexPriv} +var AllTablePrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv, DeletePriv, CreatePriv, DropPriv, AlterPriv, IndexPriv} // AllColumnPrivs is all the privileges in column scope. var AllColumnPrivs = []PrivilegeType{SelectPriv, InsertPriv, UpdatePriv} diff --git a/mysql/const_test.go b/mysql/const_test.go new file mode 100644 index 000000000..7272634c1 --- /dev/null +++ b/mysql/const_test.go @@ -0,0 +1,54 @@ +// Copyright 2017 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package mysql + +import ( + "testing" + + . "github.com/pingcap/check" +) + +var _ = Suite(&testConstSuite{}) + +type testConstSuite struct{} + +func TestT(t *testing.T) { + TestingT(t) +} + +func (s *testConstSuite) TestPrivAllConsistency(c *C) { + // AllPriv in mysql.user columns. + for priv := PrivilegeType(CreatePriv); priv != AllPriv; priv = priv << 1 { + _, ok := Priv2UserCol[priv] + c.Assert(ok, IsTrue, Commentf("priv fail %d", priv)) + } + + for _, v := range AllGlobalPrivs { + _, ok := Priv2UserCol[v] + c.Assert(ok, IsTrue) + } + + c.Assert(len(Priv2UserCol), Equals, len(AllGlobalPrivs)+1) + + for _, v := range Priv2UserCol { + _, ok := Col2PrivType[v] + c.Assert(ok, IsTrue) + } + for _, v := range Col2PrivType { + _, ok := Priv2UserCol[v] + c.Assert(ok, IsTrue) + } + + c.Assert(len(Priv2Str), Equals, len(Priv2UserCol)) +}