From 5f3b4d62d4139a1460dea4913b26da3259be09b9 Mon Sep 17 00:00:00 2001 From: Samir Faci Date: Thu, 3 Oct 2024 17:07:08 -0400 Subject: [PATCH] Updating README, .circleci and Makefile for new workflow --- .circleci/config.yml | 109 ++++------------------------------- tests/Makefile | 8 +-- tests/Readme.md | 5 -- tests/init/Readme.md | 7 +-- tests/mysql/alltypes_test.go | 3 +- tests/mysql/main_test.go | 5 ++ 6 files changed, 20 insertions(+), 117 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e21f00a4..a6d9704a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,41 +4,19 @@ version: 2.1 orbs: codecov: codecov/codecov@3.1.1 + +workflows: + version: 2 + build_and_test: + jobs: + - build_and_tests + jobs: build_and_tests: + machine: true docker: # specify the version - image: cimg/go:1.21.6 - - image: cimg/postgres:14.10 - environment: - POSTGRES_USER: jet - POSTGRES_PASSWORD: jet - POSTGRES_DB: jetdb - PGPORT: 50901 - - - image: circleci/mysql:8.0.27 - command: [ --default-authentication-plugin=mysql_native_password ] - environment: - MYSQL_ROOT_PASSWORD: jet - MYSQL_DATABASE: dvds - MYSQL_USER: jet - MYSQL_PASSWORD: jet - MYSQL_TCP_PORT: 50902 - - - image: circleci/mariadb:10.3 - command: [ '--default-authentication-plugin=mysql_native_password', '--port=50903' ] - environment: - MYSQL_ROOT_PASSWORD: jet - MYSQL_DATABASE: dvds - MYSQL_USER: jet - MYSQL_PASSWORD: jet - - - image: cockroachdb/cockroach-unstable:v23.1.0-rc.2 - command: ['start-single-node', '--accept-sql-without-tls'] - environment: - COCKROACH_USER: jet - COCKROACH_PASSWORD: jet - COCKROACH_DATABASE: jetdb environment: # environment variables for the build itself TEST_RESULTS: /tmp/test-results # path to where test results will be saved @@ -58,68 +36,6 @@ jobs: name: Install jet generator command: cd tests && make install-jet-gen - - run: - name: Waiting for Postgres to be ready - command: | - for i in `seq 1 10`; - do - nc -z localhost 50901 && echo Success && exit 0 - echo -n . - sleep 1 - done - echo Failed waiting for Postgres && exit 1 - - - run: - name: Waiting for MySQL to be ready - command: | - for i in `seq 1 10`; - do - nc -z 127.0.0.1 50902 && echo Success && exit 0 - echo -n . - sleep 1 - done - echo Failed waiting for MySQL && exit 1 - - - run: - name: Waiting for MariaDB to be ready - command: | - for i in `seq 1 10`; - do - nc -z 127.0.0.1 50903 && echo Success && exit 0 - echo -n . - sleep 1 - done - echo Failed waiting for MySQL && exit 1 - - - run: - name: Waiting for Cockroach to be ready - command: | - for i in `seq 1 10`; - do - nc -z localhost 26257 && echo Success && exit 0 - echo -n . - sleep 1 - done - echo Failed waiting for Cockroach && exit 1 - - - run: - name: Install MySQL CLI; - command: | - sudo apt-get --allow-releaseinfo-change update && sudo apt-get install default-mysql-client - - - run: - name: Create MySQL/MariaDB user and test databases - command: | - mysql -h 127.0.0.1 -P 50902 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';" - mysql -h 127.0.0.1 -P 50902 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';" - mysql -h 127.0.0.1 -P 50902 -u jet -pjet -e "create database test_sample" - mysql -h 127.0.0.1 -P 50902 -u jet -pjet -e "create database dvds2" - - mysql -h 127.0.0.1 -P 50903 -u root -pjet -e "grant all privileges on *.* to 'jet'@'%';" - mysql -h 127.0.0.1 -P 50903 -u root -pjet -e "set global sql_mode = 'STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';" - mysql -h 127.0.0.1 -P 50903 -u jet -pjet -e "create database test_sample" - mysql -h 127.0.0.1 -P 50903 -u jet -pjet -e "create database dvds2" - - run: name: Init databases command: | @@ -134,7 +50,7 @@ jobs: - run: mkdir -p $TEST_RESULTS # this will run all tests and exclude test files from code coverage report - - run: | + - run: | go test -v ./... \ -covermode=atomic \ -coverpkg=github.com/go-jet/jet/v2/postgres/...,github.com/go-jet/jet/v2/mysql/...,github.com/go-jet/jet/v2/sqlite/...,github.com/go-jet/jet/v2/qrm/...,github.com/go-jet/jet/v2/generator/...,github.com/go-jet/jet/v2/internal/... \ @@ -159,8 +75,5 @@ jobs: - store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/ path: /tmp/test-results -workflows: - version: 2 - build_and_test: - jobs: - - build_and_tests \ No newline at end of file + executor: + diff --git a/tests/Makefile b/tests/Makefile index e00c1047..0132c776 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,6 @@ -setup: checkout-testdata docker-compose-up +setup: checkout-testdata # checkout-testdata will checkout testdata from separate repository into git submodule. checkout-testdata: @@ -8,12 +8,6 @@ checkout-testdata: git submodule update cd ./testdata && git fetch && git checkout master && git pull -# docker-compose-up will download docker image for each of the databases listed in docker-compose.yaml file, and then it will initialize -# database with testdata retrieved in previous step. -# On the first run this action might take couple of minutes. Docker temp data are stored in .docker directory. -docker-compose-up: - docker-compose up - init-all: go run ./init/init.go -testsuite all diff --git a/tests/Readme.md b/tests/Readme.md index 097e5f30..569a12e2 100644 --- a/tests/Readme.md +++ b/tests/Readme.md @@ -22,8 +22,3 @@ Then we can run the tests the usual way: ```shell go test -v ./... ``` - -To removes test containers, volumes, and images: -```shell -make cleanup -``` \ No newline at end of file diff --git a/tests/init/Readme.md b/tests/init/Readme.md index 65e61d9c..e28ea46d 100644 --- a/tests/init/Readme.md +++ b/tests/init/Readme.md @@ -1,6 +1 @@ - -The `init` command can be used to initialize test databases on the local host machine, if needed. -Update [dbconfig](../dbconfig/dbconfig.go) with your local database parameters. - -The recommended way to initialize test databases is by a docker container. -See tests [Readme.md](../Readme.md). \ No newline at end of file +The `init` command can be used to initialize test databases and generate data models on the local host machine. \ No newline at end of file diff --git a/tests/mysql/alltypes_test.go b/tests/mysql/alltypes_test.go index c90f7741..110d12ac 100644 --- a/tests/mysql/alltypes_test.go +++ b/tests/mysql/alltypes_test.go @@ -1,6 +1,7 @@ package mysql import ( + "fmt" "github.com/shopspring/decimal" "github.com/stretchr/testify/require" "strings" @@ -57,7 +58,7 @@ func TestUUID(t *testing.T) { Raw("unhex(replace('dc8daae3-b83b-11e9-8eb4-98ded00c39c6','-',''))").AS("bin_uuid"), ).LIMIT(1) - //fmt.Println(query.DebugSql()) + fmt.Println(query.DebugSql()) var dest struct { UUID uuid.UUID diff --git a/tests/mysql/main_test.go b/tests/mysql/main_test.go index 7ad6c0dc..65ec3b3c 100644 --- a/tests/mysql/main_test.go +++ b/tests/mysql/main_test.go @@ -76,6 +76,11 @@ var callerLine int var callerFunction string func init() { + jetmysql.SetLogger(func(ctx context.Context, statement jetmysql.PrintableStatement) { + loggedSQL, loggedSQLArgs = statement.Sql() + loggedDebugSQL = statement.DebugSql() + }) + jetmysql.SetQueryLogger(func(ctx context.Context, info jetmysql.QueryInfo) { queryInfo = info callerFile, callerLine, callerFunction = info.Caller()