MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestParseAlterRole

Function TestParseAlterRole

pkg/sql/parser/coverage_improvement_test.go:183–482  ·  view source on GitHub ↗

TestParseAlterRole targets parseAlterRoleStatement (40.5%) and parseRoleOption (18.8%) Uses manual token construction since ROLE is not a tokenizer keyword.

(t *testing.T)

Source from the content-addressed store, hash-verified

181// TestParseAlterRole targets parseAlterRoleStatement (40.5%) and parseRoleOption (18.8%)
182// Uses manual token construction since ROLE is not a tokenizer keyword.
183func TestParseAlterRole(t *testing.T) {
184 t.Run("RENAME TO", func(t *testing.T) {
185 tokens := []token.Token{
186 {Type: models.TokenTypeAlter, Literal: "ALTER"},
187 {Type: models.TokenTypeRole, Literal: "ROLE"},
188 {Type: models.TokenTypeIdentifier, Literal: "admin"},
189 {Type: models.TokenTypeRename, Literal: "RENAME"},
190 {Type: models.TokenTypeTo, Literal: "TO"},
191 {Type: models.TokenTypeIdentifier, Literal: "superadmin"},
192 }
193 tree := parseTokensHelper(t, tokens)
194 defer ast.ReleaseAST(tree)
195
196 stmt, ok := tree.Statements[0].(*ast.AlterStatement)
197 if !ok {
198 t.Fatalf("expected AlterStatement, got %T", tree.Statements[0])
199 }
200 if stmt.Name != "admin" {
201 t.Errorf("expected name admin, got %s", stmt.Name)
202 }
203 op, ok := stmt.Operation.(*ast.AlterRoleOperation)
204 if !ok {
205 t.Fatalf("expected AlterRoleOperation, got %T", stmt.Operation)
206 }
207 if op.Type != ast.RenameRole {
208 t.Errorf("expected RenameRole, got %v", op.Type)
209 }
210 if op.NewName != "superadmin" {
211 t.Errorf("expected new name superadmin, got %s", op.NewName)
212 }
213 })
214
215 t.Run("ADD MEMBER", func(t *testing.T) {
216 tokens := []token.Token{
217 {Type: models.TokenTypeAlter, Literal: "ALTER"},
218 {Type: models.TokenTypeRole, Literal: "ROLE"},
219 {Type: models.TokenTypeIdentifier, Literal: "admins"},
220 {Type: models.TokenTypeAdd, Literal: "ADD"},
221 {Type: models.TokenTypeMember, Literal: "MEMBER"},
222 {Type: models.TokenTypeIdentifier, Literal: "john"},
223 }
224 tree := parseTokensHelper(t, tokens)
225 defer ast.ReleaseAST(tree)
226
227 stmt := tree.Statements[0].(*ast.AlterStatement)
228 op := stmt.Operation.(*ast.AlterRoleOperation)
229 if op.Type != ast.AddMember {
230 t.Errorf("expected AddMember, got %v", op.Type)
231 }
232 if op.MemberName != "john" {
233 t.Errorf("expected member john, got %s", op.MemberName)
234 }
235 })
236
237 t.Run("DROP MEMBER", func(t *testing.T) {
238 tokens := []token.Token{
239 {Type: models.TokenTypeAlter, Literal: "ALTER"},
240 {Type: models.TokenTypeRole, Literal: "ROLE"},

Callers

nothing calls this directly

Calls 5

ReleaseASTFunction · 0.92
parseTokensHelperFunction · 0.85
RunMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected