Skip to content

tests: add postgres integration tests #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,8 @@ jobs:

- name: Build
run: |
set -e
exit_status=
for f in $(find . -name go.mod)
do
pushd $(dirname $f) > /dev/null
go build ./... || exit_status=$?
popd > /dev/null
done
exit $status
go build ./...

- name: Test
run: |
set -e
exit_status=
for f in $(find . -name go.mod)
do
pushd $(dirname $f) > /dev/null
go test -test.v ./... || exit_status=$?
popd > /dev/null
done
exit $exit_status
go test ./...
50 changes: 50 additions & 0 deletions .github/workflows/tests-postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Go

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
postgres:
strategy:
matrix:
dbversion: ["postgres:latest"]
go: ["1.21", "1.20", "1.19"]
platform: [ubuntu-latest] # can not run in macOS and Windows
runs-on: ${{ matrix.platform }}

services:
postgres:
image: ${{ matrix.dbversion }}
env:
POSTGRES_PASSWORD: go_db
POSTGRES_USER: go_db
POSTGRES_DB: go_db
ports:
- 9920:5432
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Set up Go 1.x
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version: ${{ matrix.go }}

- name: Check out code into the Go module directory
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0

- name: go mod package cache
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # v3.3.1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}

- name: Tests
run: make test-postgres
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Determine this makefile's path.
# Be sure to place this BEFORE `include` directives, if any.
THIS_FILE := $(lastword $(MAKEFILE_LIST))
THIS_DIR := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))

TMP_DIR := $(shell mktemp -d)
REPO_PATH := github.com/hashicorp/mql

.PHONY: fmt
fmt:
gofumpt -w $$(find . -name '*.go')

.PHONY: test
test:
go test -race -count=1 ./...

.PHONY: test-all
test-all: test test-postgres

.PHONY: test-postgres
test-postgres:
##############################################################
# this test is dependent on first running: docker-compose up
##############################################################
cd ./tests/postgres && \
DB_DIALECT=postgres DB_DSN="postgresql://go_db:go_db@localhost:9920/go_db?sslmode=disable" go test -race -count=1 ./...
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

version: '3'

services:
postgres:
image: 'postgres:latest'
ports:
- 9920:5432
environment:
- POSTGRES_DB=go_db
- POSTGRES_USER=go_db
- POSTGRES_PASSWORD=go_db
43 changes: 43 additions & 0 deletions tests/postgres/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module github.com/hashicorp/mql/tests/postgres

go 1.20

require (
github.com/hashicorp/go-dbw v0.0.0-20230612165830-f471701ba4c2
github.com/hashicorp/mql v0.1.1-0.20230816193610-066beca8effe
github.com/stretchr/testify v1.8.4
gorm.io/driver/postgres v1.5.0
gorm.io/gorm v1.25.1
)

require (
github.com/DATA-DOG/go-sqlmock v1.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/hashicorp/go-hclog v1.4.0 // indirect
github.com/hashicorp/go-secure-stdlib/base62 v0.1.2 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgx/v4 v4.18.1 // indirect
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/lib/pq v1.10.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-sqlite3 v1.14.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/xo/dburl v0.13.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/exp v0.0.0-20230811145659-89c5cff77bcb // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/text v0.8.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/driver/sqlite v1.4.4 // indirect
)
Loading