Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor the whole package
- Loading branch information
Showing
16 changed files
with
1,525 additions
and
1,105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
name: Code Check | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
code-check: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
go: ['1.20'] | ||
|
||
name: code-check | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
steps: | ||
- name: 01_Checkout_Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: 02_Install_Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
cache: false | ||
|
||
- name: 03_Format_Code | ||
run: | | ||
go install golang.org/x/tools/cmd/goimports@latest | ||
make fmt | ||
- name: 04_Lint_Check | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
# Require: The version of golangci-lint to use. | ||
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. | ||
# When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. | ||
version: v1.53 | ||
|
||
# Optional: working directory, useful for monorepos | ||
# working-directory: somedir | ||
|
||
# Optional: golangci-lint command line arguments. | ||
# | ||
# Note: By default, the `.golangci.yml` file should be at the root of the repository. | ||
# The location of the configuration file can be changed by using `--config=` | ||
# args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 | ||
|
||
# Optional: show only new issues if it's a pull request. The default value is `false`. | ||
# only-new-issues: true | ||
|
||
# Optional: if set to true, then all caching functionality will be completely disabled, | ||
# takes precedence over all other caching options. | ||
# skip-cache: true | ||
|
||
# Optional: if set to true, then the action won't cache or restore ~/go/pkg. | ||
# skip-pkg-cache: true | ||
|
||
# Optional: if set to true, then the action won't cache or restore ~/.cache/go-build. | ||
# skip-build-cache: true | ||
|
||
# Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. | ||
# install-mode: "goinstall" | ||
|
||
- name: 05_Static_Check | ||
uses: dominikh/staticcheck-action@v1.3.0 | ||
with: | ||
version: "2023.1.3" | ||
|
||
- name: 06_Initialize_CodeQL | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
languages: 'go' | ||
queries: +security-and-quality | ||
|
||
- name: 07_Auto_Build | ||
uses: github/codeql-action/autobuild@v2 | ||
|
||
- name: 08_CodeQL_Analysis | ||
uses: github/codeql-action/analyze@v2 | ||
with: | ||
category: "/language:go" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
name: Tests | ||
|
||
on: [push, pull_request] | ||
|
||
env: | ||
TEST_DATABASE_NAME: sqladapter_test | ||
TEST_DATABASE_USER: blank | ||
TEST_DATABASE_PASSWORD: Sql-adapter_test | ||
|
||
jobs: | ||
test-all: | ||
name: test-all | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
go: | ||
- '1.20' | ||
- '1.19' | ||
- '1.18' | ||
mysql: | ||
- '8.0' | ||
postgres: | ||
- '15' | ||
sqlserver: | ||
- 'latest' | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
services: | ||
mysql: | ||
image: mysql:${{ matrix.mysql }} | ||
env: | ||
MYSQL_DATABASE: ${{ env.TEST_DATABASE_NAME }} | ||
MYSQL_ROOT_PASSWORD: ${{ env.TEST_DATABASE_PASSWORD }} | ||
MYSQL_USER: ${{ env.TEST_DATABASE_USER }} | ||
MYSQL_PASSWORD: ${{ env.TEST_DATABASE_PASSWORD }} | ||
ports: | ||
- 3306:3306 | ||
|
||
postgres: | ||
image: postgres:${{ matrix.postgres }} | ||
env: | ||
POSTGRES_DB: ${{ env.TEST_DATABASE_NAME }} | ||
POSTGRES_USER: ${{ env.TEST_DATABASE_USER }} | ||
POSTGRES_PASSWORD: ${{ env.TEST_DATABASE_PASSWORD }} | ||
ports: | ||
- 5432:5432 | ||
|
||
sqlserver: | ||
image: mcmoe/mssqldocker:${{ matrix.sqlserver }} | ||
env: | ||
ACCEPT_EULA: "Y" | ||
MSSQL_DB: ${{ env.TEST_DATABASE_NAME }} | ||
SA_PASSWORD: ${{ env.TEST_DATABASE_PASSWORD }} | ||
MSSQL_USER: ${{ env.TEST_DATABASE_USER }} | ||
MSSQL_PASSWORD: ${{ env.TEST_DATABASE_PASSWORD }} | ||
ports: | ||
- 1433:1433 | ||
|
||
steps: | ||
- name: 01_Checkout_Code | ||
uses: actions/checkout@v3 | ||
|
||
- name: 02_Install_go_${{ matrix.go }} | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: ${{ matrix.go }} | ||
|
||
- name: 03_Run_Tests | ||
run: | | ||
make run-test | ||
- name: 04_Send_Coverage | ||
uses: shogo82148/actions-goveralls@v1 | ||
with: | ||
path-to-profile: coverage.out | ||
flag-name: Go-${{ matrix.go }} | ||
parallel: true | ||
|
||
finish: | ||
needs: | ||
- test-all | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: shogo82148/actions-goveralls@v1 | ||
with: | ||
parallel-finished: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,6 @@ | |
# vendor/ | ||
|
||
.vscode | ||
.idea | ||
.idea | ||
|
||
*.db |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!make | ||
|
||
include test.env | ||
export $(shell sed 's/=.*//' test.env) | ||
|
||
define import_driver | ||
@echo 'import driver ${1}' | ||
@sed -i '16 i import _ "${1}"' helper_test.go | ||
@go get -u ${1}@${2} | ||
endef | ||
|
||
define delete_driver | ||
@sed -i 's#'${1}'#${DELETE_DRIVER_FLAG}#;/${DELETE_DRIVER_FLAG}/d' helper_test.go | ||
endef | ||
|
||
define run_test | ||
@echo "test start" | ||
@go mod tidy | ||
@CGO_ENABLED=1 go test -v -race -covermode=atomic -coverprofile=coverage.out ./... | ||
endef | ||
|
||
define start_mysql | ||
@docker run --name mysql_${TEST_DATABASE_NAME} \ | ||
-p 3306:${TEST_DATABASE_PORT_MYSQL} \ | ||
-e "MYSQL_DATABASE=${TEST_DATABASE_NAME}" \ | ||
-e "MYSQL_ROOT_PASSWORD=${TEST_DATABASE_PASSWORD}" \ | ||
-e "MYSQL_USER=${TEST_DATABASE_USER}" \ | ||
-e "MYSQL_PASSWORD=${TEST_DATABASE_PASSWORD}" \ | ||
-d --rm mysql:latest | ||
endef | ||
|
||
define start_postgres | ||
@docker run --name postgres_${TEST_DATABASE_NAME} \ | ||
-p 5432:${TEST_DATABASE_PORT_POSTGRES} \ | ||
-e "POSTGRES_DB=${TEST_DATABASE_NAME}" \ | ||
-e "POSTGRES_USER=${TEST_DATABASE_USER}" \ | ||
-e "POSTGRES_PASSWORD=${TEST_DATABASE_PASSWORD}" \ | ||
-d --rm postgres:latest | ||
endef | ||
|
||
define start_sqlserver | ||
@docker run --name sqlserver_${TEST_DATABASE_NAME} \ | ||
-p 1433:${TEST_DATABASE_PORT_SQLSERVER} \ | ||
-e "ACCEPT_EULA=Y" \ | ||
-e "MSSQL_DB=${TEST_DATABASE_NAME}" \ | ||
-e "SA_PASSWORD=${TEST_DATABASE_PASSWORD}" \ | ||
-e "MSSQL_USER=${TEST_DATABASE_USER}" \ | ||
-e "MSSQL_PASSWORD=${TEST_DATABASE_PASSWORD}" \ | ||
-d --rm mcmoe/mssqldocker:latest | ||
endef | ||
|
||
|
||
.PHONY: clean-drivers | ||
clean-drivers: | ||
@echo "clean drivers" | ||
${call delete_driver,${DRIVER_SQLITE}} | ||
${call delete_driver,${DRIVER_MYSQL}} | ||
${call delete_driver,${DRIVER_POSTGRES}} | ||
${call delete_driver,${DRIVER_SQLSERVER}} | ||
|
||
clean: clean-drivers | ||
@go mod tidy | ||
@go fmt ./... | ||
|
||
run-test: clean-drivers | ||
${call import_driver,${DRIVER_SQLITE},${DRIVER_SQLITE_VERSION}} | ||
${call import_driver,${DRIVER_MYSQL},${DRIVER_MYSQL_VERSION}} | ||
${call import_driver,${DRIVER_POSTGRES},${DRIVER_POSTGRES_VERSION}} | ||
${call import_driver,${DRIVER_SQLSERVER},${DRIVER_SQLSERVER_VERSION}} | ||
${call run_test} | ||
|
||
test-all: clean-drivers | ||
${call start_mysql} | ||
${call start_postgres} | ||
${call start_sqlserver} | ||
@sleep 10 | ||
${call import_driver,${DRIVER_SQLITE},${DRIVER_SQLITE_VERSION}} | ||
${call import_driver,${DRIVER_MYSQL},${DRIVER_MYSQL_VERSION}} | ||
${call import_driver,${DRIVER_POSTGRES},${DRIVER_POSTGRES_VERSION}} | ||
${call import_driver,${DRIVER_SQLSERVER},${DRIVER_SQLSERVER_VERSION}} | ||
${call run_test} | ||
@docker stop mysql_${TEST_DATABASE_NAME} | ||
@docker stop postgres_${TEST_DATABASE_NAME} | ||
@docker stop sqlserver_${TEST_DATABASE_NAME} | ||
|
||
test-sqlite: clean-drivers | ||
${call import_driver,${DRIVER_SQLITE},${DRIVER_SQLITE_VERSION}} | ||
${call run_test} | ||
|
||
test-mysql: clean-drivers | ||
${call start_mysql} | ||
@sleep 10 | ||
${call import_driver,${DRIVER_MYSQL},${DRIVER_MYSQL_VERSION}} | ||
${call run_test} | ||
@docker stop mysql_${TEST_DATABASE_NAME} | ||
|
||
test-postgres: clean-drivers | ||
${call start_postgres} | ||
@sleep 10 | ||
${call import_driver,${DRIVER_POSTGRES},${DRIVER_POSTGRES_VERSION}} | ||
${call run_test} | ||
@docker stop postgres_${TEST_DATABASE_NAME} | ||
|
||
test-sqlserver: clean-drivers | ||
${call start_sqlserver} | ||
@sleep 10 | ||
${call import_driver,${DRIVER_SQLSERVER},${DRIVER_SQLSERVER_VERSION}} | ||
${call run_test} | ||
@docker stop sqlserver_${TEST_DATABASE_NAME} | ||
|
||
lint: | ||
golangci-lint run ./... | ||
|
||
fmt: | ||
goimports -l -w -d -e . | ||
|
||
build: | ||
go build -v . |
Oops, something went wrong.