capabilities_test.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package capabilities
  2. import (
  3. "encoding/json"
  4. "testing"
  5. "github.com/danfragoso/pizzasql-next/pkg/pgerror"
  6. "github.com/danfragoso/pizzasql-next/pkg/version"
  7. )
  8. func TestCurrentDocumentIsVersionedAndMarshalable(t *testing.T) {
  9. doc := Current()
  10. if doc.SchemaVersion != SchemaVersion {
  11. t.Fatalf("schema version = %d, want %d", doc.SchemaVersion, SchemaVersion)
  12. }
  13. if doc.Engine != "pizzasql" || doc.EngineVersion != version.String() {
  14. t.Fatalf("engine identity = %q/%q", doc.Engine, doc.EngineVersion)
  15. }
  16. body, err := json.Marshal(doc)
  17. if err != nil {
  18. t.Fatalf("marshal: %v", err)
  19. }
  20. var round Document
  21. if err := json.Unmarshal(body, &round); err != nil {
  22. t.Fatalf("unmarshal: %v", err)
  23. }
  24. if round.Constraints.Unique.SQLState != "23505" {
  25. t.Fatalf("unique SQLSTATE = %q, want 23505", round.Constraints.Unique.SQLState)
  26. }
  27. if round.Transactions.SerializationCode != "40001" {
  28. t.Fatalf("serialization SQLSTATE = %q, want 40001", round.Transactions.SerializationCode)
  29. }
  30. if round.ErrorCodes["0A000"] != "feature_not_supported" {
  31. t.Fatalf("0A000 mapping = %q", round.ErrorCodes["0A000"])
  32. }
  33. if !round.Notifications.Listen.Supported || !round.Notifications.Notify.Supported {
  34. t.Fatal("LISTEN/NOTIFY should be advertised as supported")
  35. }
  36. if round.Notifications.PayloadLimit != 8000 || round.Notifications.DurableReplay {
  37. t.Fatalf("unexpected notification limits: %+v", round.Notifications)
  38. }
  39. if !round.DDL.RenameColumnIndexes.Supported {
  40. t.Fatal("RENAME COLUMN must advertise index metadata rewriting")
  41. }
  42. }
  43. func TestJSONArrowOperatorsAreAdvertised(t *testing.T) {
  44. arrow := Current().JSON.ArrowOperators
  45. if !arrow.Supported {
  46. t.Fatal("-> and ->> should be advertised as supported")
  47. }
  48. if arrow.SQLState != "" {
  49. t.Fatalf("arrow operator SQLSTATE = %q, want none", arrow.SQLState)
  50. }
  51. if arrow.Status == "rejected" {
  52. t.Fatalf("arrow operator status = %q, want a supported status", arrow.Status)
  53. }
  54. }
  55. func TestAddColumnBackfillIsAdvertised(t *testing.T) {
  56. doc := Current()
  57. if !doc.DDL.AddColumnBackfill.Supported {
  58. t.Fatalf("add_column_backfill = %+v, want supported", doc.DDL.AddColumnBackfill)
  59. }
  60. if doc.DDL.AddColumnBackfill.Status != "rewrites_rows" {
  61. t.Fatalf("add_column_backfill status = %q, want rewrites_rows", doc.DDL.AddColumnBackfill.Status)
  62. }
  63. if doc.DDL.AddColumn.Status == "metadata_only" {
  64. t.Fatalf("add_column status = %q, but a constant DEFAULT rewrites rows", doc.DDL.AddColumn.Status)
  65. }
  66. }
  67. func TestCheckConstraintIsAdvertised(t *testing.T) {
  68. doc := Current()
  69. check := doc.Constraints.Check
  70. if !check.Supported {
  71. t.Fatalf("check = %+v, want supported", check)
  72. }
  73. if check.Status != "enforced" {
  74. t.Fatalf("check status = %q, want enforced", check.Status)
  75. }
  76. if check.SQLState != pgerror.CodeCheckViolation {
  77. t.Fatalf("check SQLSTATE = %q, want %q", check.SQLState, pgerror.CodeCheckViolation)
  78. }
  79. if check.Notes == "" {
  80. t.Fatal("check notes must describe the enforcement surface")
  81. }
  82. if got := doc.ErrorCodes[pgerror.CodeCheckViolation]; got != "check_violation" {
  83. t.Fatalf("23514 mapping = %q, want check_violation", got)
  84. }
  85. }