capabilities_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package capabilities
  2. import (
  3. "encoding/json"
  4. "testing"
  5. "github.com/danfragoso/pizzasql-next/pkg/version"
  6. )
  7. func TestCurrentDocumentIsVersionedAndMarshalable(t *testing.T) {
  8. doc := Current()
  9. if doc.SchemaVersion != SchemaVersion {
  10. t.Fatalf("schema version = %d, want %d", doc.SchemaVersion, SchemaVersion)
  11. }
  12. if doc.Engine != "pizzasql" || doc.EngineVersion != version.String() {
  13. t.Fatalf("engine identity = %q/%q", doc.Engine, doc.EngineVersion)
  14. }
  15. body, err := json.Marshal(doc)
  16. if err != nil {
  17. t.Fatalf("marshal: %v", err)
  18. }
  19. var round Document
  20. if err := json.Unmarshal(body, &round); err != nil {
  21. t.Fatalf("unmarshal: %v", err)
  22. }
  23. if round.Constraints.Unique.SQLState != "23505" {
  24. t.Fatalf("unique SQLSTATE = %q, want 23505", round.Constraints.Unique.SQLState)
  25. }
  26. if round.Transactions.SerializationCode != "40001" {
  27. t.Fatalf("serialization SQLSTATE = %q, want 40001", round.Transactions.SerializationCode)
  28. }
  29. if round.ErrorCodes["0A000"] != "feature_not_supported" {
  30. t.Fatalf("0A000 mapping = %q", round.ErrorCodes["0A000"])
  31. }
  32. }