From 09e0cc481535b99d4b39370ee3250b392bc3464c Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Thu, 12 Nov 2015 15:27:20 -0600 Subject: [PATCH] Skip JSON tests for old PostgreSQL servers --- stdlib/sql_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/stdlib/sql_test.go b/stdlib/sql_test.go index e15c9744..83a7d949 100644 --- a/stdlib/sql_test.go +++ b/stdlib/sql_test.go @@ -440,6 +440,10 @@ func TestConnQueryJSONIntoByteSlice(t *testing.T) { db := openDB(t) defer closeDB(t, db) + if !serverHasJSON(t, db) { + t.Skip("Skipping due to server's lack of JSON type") + } + _, err := db.Exec(` create temporary table docs( body json not null @@ -476,6 +480,10 @@ func TestConnExecInsertByteSliceIntoJSON(t *testing.T) { db := openDB(t) defer closeDB(t, db) + if !serverHasJSON(t, db) { + t.Skip("Skipping due to server's lack of JSON type") + } + _, err := db.Exec(` create temporary table docs( body json not null @@ -510,6 +518,15 @@ func TestConnExecInsertByteSliceIntoJSON(t *testing.T) { ensureConnValid(t, db) } +func serverHasJSON(t *testing.T, db *sql.DB) bool { + var hasJSON bool + err := db.QueryRow(`select true from pg_type where typname='json'`).Scan(&hasJSON) + if err != nil { + t.Fatalf("db.QueryRow unexpectedly failed: %v", err) + } + return hasJSON +} + func TestTransactionLifeCycle(t *testing.T) { db := openDB(t) defer closeDB(t, db)