From aa7fd69b976b4830a4bc7759b373f2fcb5be47b2 Mon Sep 17 00:00:00 2001 From: Ariel Mashraki <7413593+a8m@users.noreply.github.com> Date: Sat, 27 Feb 2021 19:27:10 +0200 Subject: [PATCH] ci/integration: update integration executor (#33) --- .circleci/config.yml | 85 ++++++++++++++++++++++++++------- .travis.yml | 14 ------ bench_test.go | 16 +++++-- go.mod | 8 +++- go.sum | 30 ++++++++++++ integration/Dockerfile | 5 -- integration/Makefile | 5 -- integration/docker-compose.yaml | 20 -------- integration/rql_test.go | 4 +- 9 files changed, 118 insertions(+), 69 deletions(-) delete mode 100644 .travis.yml delete mode 100644 integration/Dockerfile delete mode 100644 integration/Makefile delete mode 100644 integration/docker-compose.yaml diff --git a/.circleci/config.yml b/.circleci/config.yml index ae14f06..c8576a3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,29 +1,78 @@ -version: 2 +version: 2.1 + +aliases: + - &mktestdir + run: + name: Create results directory + command: mkdir -p ~/test-results + + - &storetestdir + store_test_results: + path: ~/test-results + +orbs: + go: circleci/go@1.5.0 + +commands: + getmods: + steps: + - go/load-cache + - go/mod-download + - go/save-cache + jobs: - unit: + lint: docker: - - image: circleci/golang:1.16 - working_directory: /go/src/github.com/a8m/rql + - image: golangci/golangci-lint:v1.28-alpine + steps: + - checkout + - *mktestdir + - run: + name: Run linters + command: golangci-lint run --timeout 5m --out-format junit-xml > ~/test-results/lint.xml + - *storetestdir + unit: + executor: + name: go/default + tag: '1.16' steps: - checkout - - run: go get -v -t -d ./... - - run: go test -v - + - *mktestdir + - getmods + - run: + name: Unit tests + command: gotestsum -f short-verbose --junitfile ~/test-results/rql.xml + working_directory: . + - *storetestdir integration: - machine: - image: circleci/classic:201808-01 - working_directory: /home/circleci/.go_workspace/src/github.com/a8m/rql - environment: - GOPATH: /home/circleci/.go_workspace + docker: &integration-docker + - image: circleci/golang:1.16 + environment: + MYSQL_DSN: root:pass@tcp(localhost:3306)/test + - image: circleci/mysql + environment: + MYSQL_DATABASE: test + MYSQL_ROOT_PASSWORD: pass steps: - - checkout - - run: make -C integration test + - checkout + - run: &integration-wait + name: Wait for databases + command: >- + dockerize -timeout 2m + -wait tcp://localhost:3306 + - *mktestdir + - getmods + - run: + name: Run integration tests + working_directory: integration + command: gotestsum -f short-verbose --junitfile ~/test-results/integration.xml -- -race . + - *storetestdir workflows: - version: 2 + version: 2.1 all: jobs: + - lint - unit - - integration: - requires: - - unit + - integration + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 17b8566..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -sudo: required -language: go - -go: - - "1.13.x" - - "1.14.x" - - master - -services: - - docker - -script: - - go test -v - - make -C integration test diff --git a/bench_test.go b/bench_test.go index 2254e6b..5d4aaae 100644 --- a/bench_test.go +++ b/bench_test.go @@ -38,7 +38,7 @@ var p = MustNewParser(Config{ func BenchmarkLargeQuery(b *testing.B) { for i := 0; i < b.N; i++ { - p.Parse([]byte(`{ + _, err := p.Parse([]byte(`{ "filter": { "admin": true, "name": "foo", @@ -64,12 +64,15 @@ func BenchmarkLargeQuery(b *testing.B) { "offset": 100, "limit": 10 }`)) + if err != nil { + b.Error(err) + } } } func BenchmarkMediumQuery(b *testing.B) { for i := 0; i < b.N; i++ { - p.Parse([]byte(`{ + _, err := p.Parse([]byte(`{ "filter": { "name": "foo", "address.name": "bar", @@ -83,12 +86,16 @@ func BenchmarkMediumQuery(b *testing.B) { "offset": 100, "limit": 10 }`)) + if err != nil { + b.Error(err) + } + } } func BenchmarkSmallQuery(b *testing.B) { for i := 0; i < b.N; i++ { - p.Parse([]byte(`{ + _, err := p.Parse([]byte(`{ "filter": { "address.name": "TLV", "admin": true @@ -96,5 +103,8 @@ func BenchmarkSmallQuery(b *testing.B) { "offset": 25, "limit": 10 }`)) + if err != nil { + b.Error(err) + } } } diff --git a/go.mod b/go.mod index 182a979..85ad4f5 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,9 @@ module github.com/a8m/rql -require github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 +require ( + github.com/go-sql-driver/mysql v1.5.0 // indirect + github.com/jinzhu/gorm v1.9.16 // indirect + github.com/mailru/easyjson v0.7.7 +) -go 1.13 +go 1.16 diff --git a/go.sum b/go.sum index 4677bd2..6b60a04 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,32 @@ +github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= +github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= +github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= +github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= +github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o= +github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs= +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA= +github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/integration/Dockerfile b/integration/Dockerfile deleted file mode 100644 index fbdaf21..0000000 --- a/integration/Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM golang - -RUN go get github.com/mailru/easyjson -RUN go get github.com/jinzhu/gorm -RUN go get github.com/go-sql-driver/mysql diff --git a/integration/Makefile b/integration/Makefile deleted file mode 100644 index 4fbf6bf..0000000 --- a/integration/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -test: - docker build . - docker-compose up -d --scale integration=0 - docker-compose run integration - docker-compose down \ No newline at end of file diff --git a/integration/docker-compose.yaml b/integration/docker-compose.yaml deleted file mode 100644 index b49c853..0000000 --- a/integration/docker-compose.yaml +++ /dev/null @@ -1,20 +0,0 @@ -version: '3' -services: - - integration: - build: . - environment: - - CONN_STRING=root:pass@tcp(mysql:3306)/test - depends_on: - - mysql - volumes: - - ../:/go/src/github.com/a8m/rql - command: ['go', 'test', '-v', 'github.com/a8m/rql/integration'] - - mysql: - image: mysql - environment: - MYSQL_ROOT_PASSWORD: pass - MYSQL_DATABASE: test - healthcheck: - test: mysql -ppass -e "show databases" diff --git a/integration/rql_test.go b/integration/rql_test.go index af95b05..ac985d7 100644 --- a/integration/rql_test.go +++ b/integration/rql_test.go @@ -14,7 +14,7 @@ import ( var ( CreateTime, _ = time.Parse(time.RFC3339, "2000-05-16T16:00:00.000Z") - MySQLConn = os.Getenv("CONN_STRING") + MySQLConn = os.Getenv("MYSQL_DSN") QueryParser = rql.MustNewParser(rql.Config{ Model: User{}, FieldSep: ".", @@ -117,7 +117,7 @@ func AssertSelect(t *testing.T, db *gorm.DB, expected []string, query string) { func Connect(t *testing.T) *gorm.DB { if MySQLConn == "" { - t.Fatal("missing database connection string") + t.Skip("missing database connection string") } for i := 1; i <= 5; i++ { db, err := gorm.Open("mysql", MySQLConn)