Skip to content

Commit

Permalink
Updating README, .circleci and Makefile for new workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
safaci2000 committed Oct 3, 2024
1 parent 08124be commit 5f3b4d6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 117 deletions.
109 changes: 11 additions & 98 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,19 @@
version: 2.1
orbs:
codecov: codecov/[email protected]

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
Expand All @@ -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: |
Expand All @@ -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/... \
Expand All @@ -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
executor:

8 changes: 1 addition & 7 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@


setup: checkout-testdata docker-compose-up
setup: checkout-testdata

# checkout-testdata will checkout testdata from separate repository into git submodule.
checkout-testdata:
git submodule init
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

Expand Down
5 changes: 0 additions & 5 deletions tests/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
7 changes: 1 addition & 6 deletions tests/init/Readme.md
Original file line number Diff line number Diff line change
@@ -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).
The `init` command can be used to initialize test databases and generate data models on the local host machine.
3 changes: 2 additions & 1 deletion tests/mysql/alltypes_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mysql

import (
"fmt"
"github.com/shopspring/decimal"
"github.com/stretchr/testify/require"
"strings"
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/mysql/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5f3b4d6

Please sign in to comment.