TestParseAlterPolicy targets parseAlterPolicyStatement (50.0%) Uses manual token construction since POLICY is not a tokenizer keyword.
(t *testing.T)
| 484 | // TestParseAlterPolicy targets parseAlterPolicyStatement (50.0%) |
| 485 | // Uses manual token construction since POLICY is not a tokenizer keyword. |
| 486 | func TestParseAlterPolicy(t *testing.T) { |
| 487 | t.Run("RENAME TO", func(t *testing.T) { |
| 488 | tokens := []token.Token{ |
| 489 | {Type: models.TokenTypeAlter, Literal: "ALTER"}, |
| 490 | {Type: models.TokenTypePolicy, Literal: "POLICY"}, |
| 491 | {Type: models.TokenTypeIdentifier, Literal: "user_policy"}, |
| 492 | {Type: models.TokenTypeOn, Literal: "ON"}, |
| 493 | {Type: models.TokenTypeIdentifier, Literal: "users"}, |
| 494 | {Type: models.TokenTypeRename, Literal: "RENAME"}, |
| 495 | {Type: models.TokenTypeTo, Literal: "TO"}, |
| 496 | {Type: models.TokenTypeIdentifier, Literal: "new_policy"}, |
| 497 | } |
| 498 | tree := parseTokensHelper(t, tokens) |
| 499 | defer ast.ReleaseAST(tree) |
| 500 | |
| 501 | stmt := tree.Statements[0].(*ast.AlterStatement) |
| 502 | op := stmt.Operation.(*ast.AlterPolicyOperation) |
| 503 | if op.Type != ast.RenamePolicy { |
| 504 | t.Errorf("expected RenamePolicy, got %v", op.Type) |
| 505 | } |
| 506 | if op.NewName != "new_policy" { |
| 507 | t.Errorf("expected new_policy, got %s", op.NewName) |
| 508 | } |
| 509 | }) |
| 510 | |
| 511 | t.Run("with TO roles", func(t *testing.T) { |
| 512 | tokens := []token.Token{ |
| 513 | {Type: models.TokenTypeAlter, Literal: "ALTER"}, |
| 514 | {Type: models.TokenTypePolicy, Literal: "POLICY"}, |
| 515 | {Type: models.TokenTypeIdentifier, Literal: "user_policy"}, |
| 516 | {Type: models.TokenTypeOn, Literal: "ON"}, |
| 517 | {Type: models.TokenTypeIdentifier, Literal: "users"}, |
| 518 | {Type: models.TokenTypeTo, Literal: "TO"}, |
| 519 | {Type: models.TokenTypeIdentifier, Literal: "admin"}, |
| 520 | {Type: models.TokenTypeComma, Literal: ","}, |
| 521 | {Type: models.TokenTypeIdentifier, Literal: "manager"}, |
| 522 | } |
| 523 | tree := parseTokensHelper(t, tokens) |
| 524 | defer ast.ReleaseAST(tree) |
| 525 | |
| 526 | stmt := tree.Statements[0].(*ast.AlterStatement) |
| 527 | op := stmt.Operation.(*ast.AlterPolicyOperation) |
| 528 | if op.Type != ast.ModifyPolicy { |
| 529 | t.Errorf("expected ModifyPolicy, got %v", op.Type) |
| 530 | } |
| 531 | if len(op.To) != 2 { |
| 532 | t.Fatalf("expected 2 TO roles, got %d", len(op.To)) |
| 533 | } |
| 534 | }) |
| 535 | |
| 536 | t.Run("with USING", func(t *testing.T) { |
| 537 | tokens := []token.Token{ |
| 538 | {Type: models.TokenTypeAlter, Literal: "ALTER"}, |
| 539 | {Type: models.TokenTypePolicy, Literal: "POLICY"}, |
| 540 | {Type: models.TokenTypeIdentifier, Literal: "user_policy"}, |
| 541 | {Type: models.TokenTypeOn, Literal: "ON"}, |
| 542 | {Type: models.TokenTypeIdentifier, Literal: "users"}, |
| 543 | {Type: models.TokenTypeUsing, Literal: "USING"}, |
nothing calls this directly
no test coverage detected