From e68c7e2c61819177b066372851bf11a53336fccc Mon Sep 17 00:00:00 2001 From: Dan Sosedoff Date: Tue, 5 Jun 2018 18:20:58 -0500 Subject: [PATCH] Add cockroachdb smoke test --- Makefile | 1 + data/roach.sql | 43 ++++++++++++++++++++++++++++++ script/test_all.sh | 3 ++- script/test_cockroach.sh | 56 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 data/roach.sql create mode 100755 script/test_cockroach.sh diff --git a/Makefile b/Makefile index 6635f1e..ce59dec 100644 --- a/Makefile +++ b/Makefile @@ -29,6 +29,7 @@ test: test-all: @./script/test_all.sh + @./script/test_cockroach.sh assets: static/ go-bindata -o pkg/data/bindata.go -pkg data $(BINDATA_OPTS) $(BINDATA_IGNORE) -ignore=[.]gitignore -ignore=[.]gitkeep $<... diff --git a/data/roach.sql b/data/roach.sql new file mode 100644 index 0000000..c969947 --- /dev/null +++ b/data/roach.sql @@ -0,0 +1,43 @@ +DROP DATABASE IF EXISTS "roach"; +CREATE DATABASE "roach"; +USE "roach"; + +CREATE TABLE product_information ( + product_id INT PRIMARY KEY NOT NULL, + product_name STRING(50) UNIQUE NOT NULL, + product_description STRING(2000), + category_id STRING(1) NOT NULL CHECK (category_id IN ('A','B','C')), + weight_class INT, + warranty_period INT CONSTRAINT valid_warranty CHECK (warranty_period BETWEEN 0 AND 24), + supplier_id INT, + product_status STRING(20), + list_price DECIMAL(8,2), + min_price DECIMAL(8,2), + catalog_url STRING(50) UNIQUE, + date_added DATE DEFAULT CURRENT_DATE(), + misc JSONB, + CONSTRAINT price_check CHECK (list_price >= min_price), + INDEX date_added_idx (date_added), + INDEX supp_id_prod_status_idx (supplier_id, product_status), + INVERTED INDEX details (misc) +); + +INSERT INTO product_information VALUES + (1, 'Product A', 'Text', 'A', NULL, 1), + (2, 'Product B', 'Text', 'B', NULL, 2), + (3, 'Product C', 'Text', 'C', NULL, 3); + +CREATE TABLE customers ( + id INT PRIMARY KEY, + name STRING +); + +CREATE TABLE orders ( + id INT PRIMARY KEY, + customer_id INT REFERENCES customers(id) ON DELETE CASCADE +); + +INSERT INTO customers VALUES (1, 'Lauren'); +INSERT INTO orders VALUES (1,1); +DELETE FROM customers WHERE id = 1; +SELECT * FROM orders; \ No newline at end of file diff --git a/script/test_all.sh b/script/test_all.sh index 902f44a..e368fd4 100755 --- a/script/test_all.sh +++ b/script/test_all.sh @@ -30,4 +30,5 @@ do sleep 5 make test echo "-------------------------------- END TEST --------------------------------" -done \ No newline at end of file +done + diff --git a/script/test_cockroach.sh b/script/test_cockroach.sh new file mode 100755 index 0000000..7f92f05 --- /dev/null +++ b/script/test_cockroach.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +set -e + +function killproc() { + lsof -i tcp:8888 | grep pgweb | awk '{print $2}' | uniq | xargs kill +} + +# Nuke the old container if exists. +docker rm -f cockroach || true + +# Start cockroach on 26258 so we dont mess with local server. +docker run \ + --name=cockroach \ + -d \ + -t \ + -p 26258:26257 \ + cockroachdb/cockroach \ + start --insecure + +sleep 3 + +# Load the demo database. +docker exec -i cockroach ./cockroach sql --insecure < ./data/roach.sql + +# Find and destroy the existing pgweb process. +# Would be great if pgweb had --pid option. +killproc + +# Start pgweb and connect to cockroach. +make build + +./pgweb \ + --url=postgres://root@localhost:26258/roach?sslmode=disable \ + --listen=8888 \ + --skip-open & + +sleep 1 + +# Run smoke tests +base="-w \"\n\" -f http://localhost:8888/api" +table="product_information" + +curl $base/info +curl $base/connection +curl $base/schemas +curl $base/objects +curl $base/query -F query='select * from product_information;' +curl $base/tables/$table +curl $base/tables/$table/rows +curl $base/tables/$table/info +curl $base/tables/$table/indexes +curl $base/tables/$table/constraints + +# Cleanup +killproc \ No newline at end of file