Skip to content

Commit

Permalink
Init Postgres test (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm authored Jan 27, 2022
1 parent 746f28f commit ab19583
Show file tree
Hide file tree
Showing 30 changed files with 5,681 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ on:
- main
pull_request:
jobs:
golangci:
name: golangci-lint
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -36,3 +36,9 @@ jobs:

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true

- name: gherkin-lint
uses: nhatthm/[email protected]
with:
feature_files: tests/features/*
config_file: tests/.gherkin-lintrc
51 changes: 51 additions & 0 deletions .github/workflows/test-compatibility-libpq.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: test

on:
push:
branches:
- master
pull_request:

env:
GO111MODULE: "on"

jobs:
compatibility-test-libpq:
strategy:
fail-fast: false
matrix:
go-version: [ 1.16.x, 1.17.x ]
arch: [ "386", amd64 ]
postgres-version: [ "12", "13", "14" ]
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- name: Go cache
uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-compatibility-postgres-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-compatibility-postgres-cache
- name: Test
id: test
env:
GOARCH: ${{ matrix.arch }}
COMPATIBILITY_TEST: postgres
POSTGRES_VERSION: ${{ matrix.postgres-version }}-alpine
POSTGRES_DRIVER: postgres
run: |
make test-compatibility
51 changes: 51 additions & 0 deletions .github/workflows/test-compatibility-pgx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: test

on:
push:
branches:
- master
pull_request:

env:
GO111MODULE: "on"

jobs:
compatibility-test-pgx:
strategy:
fail-fast: false
matrix:
go-version: [ 1.16.x, 1.17.x ]
arch: [ "386", amd64 ]
postgres-version: [ "12", "13", "14" ]
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- name: Go cache
uses: actions/cache@v2
with:
# In order:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ matrix.go-version }}-compatibility-postgres-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ matrix.go-version }}-compatibility-postgres-cache
- name: Test
id: test
env:
GOARCH: ${{ matrix.arch }}
COMPATIBILITY_TEST: postgres
POSTGRES_VERSION: ${{ matrix.postgres-version }}-alpine
POSTGRES_DRIVER: pgx
run: |
make test-compatibility
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
env:
GOARCH: ${{ matrix.arch }}
run: |
make test
make test-unit
- name: Upload code coverage (unit)
if: matrix.go-version == env.GO_LATEST_VERSION
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
*.out

# Dependency directories (remove the comment below to include it)
/vendor
vendor

*.coverprofile
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ VENDOR_DIR = vendor

GO ?= go
GOLANGCI_LINT ?= golangci-lint
GHERKIN_LINT ?= gherkin-lint

TEST_FLAGS = -race
COMPATIBILITY_TEST ?= postgres

ifeq ($(GOARCH), 386)
TEST_FLAGS =
endif

.PHONY: $(VENDOR_DIR) lint test test-unit
.PHONY: $(VENDOR_DIR) lint test test-unit test-compatibility

$(VENDOR_DIR):
@mkdir -p $(VENDOR_DIR)
Expand All @@ -18,10 +20,17 @@ $(VENDOR_DIR):

lint:
@$(GOLANGCI_LINT) run
@$(GHERKIN_LINT) -c tests/.gherkin-lintrc tests/features/*

test: test-unit

## Run unit tests
test-unit:
@echo ">> unit test"
@$(GO) test -gcflags=-l -coverprofile=unit.coverprofile -covermode=atomic $(TEST_FLAGS) ./...

test-compatibility:
@echo ">> compatibility test"
@echo ">> COMPATIBILITY_TEST = $(COMPATIBILITY_TEST)"
@echo
@cd "tests/$(COMPATIBILITY_TEST)"; $(GO) test -gcflags=-l -v ./...
31 changes: 25 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OpenTelemetry SQL database driver wrapper for Go

[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/otelsql)](https://github.com/nhatthm/otelsql/releases/latest)
[![Build Status](https://github.com/nhatthm/otelsql/actions/workflows/unit-test.yaml/badge.svg)](https://github.com/nhatthm/otelsql/actions/workflows/unit-test.yaml)
[![Build Status](https://github.com/nhatthm/otelsql/actions/workflows/test-unit.yaml/badge.svg)](https://github.com/nhatthm/otelsql/actions/workflows/test-unit.yaml)
[![codecov](https://codecov.io/gh/nhatthm/otelsql/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/otelsql)
[![Go Report Card](https://goreportcard.com/badge/github.com/nhatthm/otelsql)](https://goreportcard.com/report/github.com/nhatthm/otelsql)
[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/nhatthm/otelsql)
Expand Down Expand Up @@ -555,9 +555,9 @@ The traces are almost identical with some minor changes:
<code>DATA-DOG/go-sqlmock</code>
</td>
<td colspan="6" align="center">
<a href="https://github.com/nhatthm/otelsql/actions/workflows/unit-test.yaml">
<a href="https://github.com/nhatthm/otelsql/actions/workflows/test-unit.yaml">
<img
src="https://github.com/nhatthm/otelsql/actions/workflows/unit-test.yaml/badge.svg" alt="Build Status"
src="https://github.com/nhatthm/otelsql/actions/workflows/test-unit.yaml/badge.svg" alt="Build Status"
style="max-width: 100%;">
</a>
</td>
Expand All @@ -567,18 +567,37 @@ The traces are almost identical with some minor changes:
<code>jmoiron/sqlx</code>
</td>
<td colspan="6" align="center">
Manually tested
<img src="https://img.shields.io/badge/manual%20test-passing-brightgreen?labelColor=3F4750&logo=target&logoWidth=10&logoColor=959DA5&color=31C754" alt="Manually Tested">
</td>
</tr>
<tr>
<td>
<code>jackc/pgx/stdlib</code>
</td>
<td>
Postgres 12
Postgres 12, 13, 14
</td>
<td colspan="6" align="center">
✅ Manually tested
<a href="https://github.com/nhatthm/otelsql/actions/workflows/test-compatibility-pgx.yaml">
<img
src="https://github.com/nhatthm/otelsql/actions/workflows/test-compatibility-pgx.yaml/badge.svg" alt="Build Status"
style="max-width: 100%;">
</a>
</td>
</tr>
<tr>
<td>
<code>lib/pq</code>
</td>
<td>
Postgres 12, 13, 14
</td>
<td colspan="6" align="center">
<a href="https://github.com/nhatthm/otelsql/actions/workflows/test-compatibility-libpq.yaml">
<img
src="https://github.com/nhatthm/otelsql/actions/workflows/test-compatibility-libpq.yaml/badge.svg" alt="Build Status"
style="max-width: 100%;">
</a>
</td>
</tr>
<tbody>
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ignore:
- "features/**/*"
- "internal/**/*"
- "tests/**/*"
78 changes: 78 additions & 0 deletions tests/.gherkin-lintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"file-name": [
"on",
{
"style": "PascalCase"
}
],
"no-files-without-scenarios": "on",
"no-unnamed-features": "on",
"no-unnamed-scenarios": "on",
"no-dupe-scenario-names": [
"on",
"in-feature"
],
"no-dupe-feature-names": "on",
"no-partially-commented-tag-lines": "on",
"indentation": [
"on",
{
"Feature": 0,
"Background": 4,
"Scenario": 4,
"Step": 8,
"Examples": 8,
"example": 12,
"given": 8,
"when": 8,
"then": 8,
"and": 8,
"but": 8,
"feature tag": 0,
"scenario tag": 4
}
],
"no-trailing-spaces": "on",
"new-line-at-eof": [
"on",
"yes"
],
"no-multiple-empty-lines": "on",
"no-empty-file": "on",
"no-scenario-outlines-without-examples": "on",
"name-length": [
"on",
{
"Feature": 120,
"Scenario": 120,
"Step": 120
}
],
"no-restricted-tags": [
"on",
{
"tags": [
"@dev",
"@watch",
"@wip"
]
}
],
"use-and": "on",
"no-duplicate-tags": "on",
"no-superfluous-tags": "on",
"no-homogenous-tags": "on",
"one-space-between-tags": "on",
"no-unused-variables": "on",
"no-background-only-scenario": "on",
"no-empty-background": "on",
"scenario-size": [
"on",
{
"steps-length": {
"Background": 30,
"Scenario": 30
}
}
]
}
Loading

0 comments on commit ab19583

Please sign in to comment.