Browse Source

Add makefile (#1531)

Fix drone

Fix ci

Add deps

Improve drone

Fix envs

Add makefile

Reviewed-on: #1531
tags/v0.8.2
Lunny Xiao 1 month ago
parent
commit
22aef2cd32
41 changed files with 485 additions and 150 deletions
  1. +0
    -61
      .circleci/config.yml
  2. +216
    -24
      .drone.yml
  3. +25
    -0
      .revive.toml
  4. +190
    -0
      Makefile
  5. +1
    -1
      cache_lru_test.go
  6. +2
    -2
      cache_memory_store_test.go
  7. +3
    -3
      engine.go
  8. +1
    -1
      examples/cache/cache.go
  9. +1
    -1
      examples/cache_gorountine/cache_goroutine.go
  10. +1
    -1
      examples/conversion/conversion.go
  11. +1
    -1
      examples/derive/derive.go
  12. +1
    -1
      examples/find/find.go
  13. +1
    -1
      examples/goroutine/goroutine.go
  14. +1
    -1
      examples/mapping/single_mapping.go
  15. +1
    -1
      examples/max_connect/max_connect.go
  16. +1
    -1
      examples/sync/sync.go
  17. +1
    -1
      examples/tables/tables.go
  18. +1
    -1
      migrate/migrate_test.go
  19. +1
    -1
      session_cond_test.go
  20. +1
    -1
      session_delete_test.go
  21. +1
    -1
      session_find_test.go
  22. +13
    -13
      session_insert_test.go
  23. +1
    -1
      session_pk_test.go
  24. +1
    -1
      session_stats_test.go
  25. +1
    -1
      session_tx_test.go
  26. +3
    -3
      session_update_test.go
  27. +1
    -1
      tag.go
  28. +1
    -1
      tag_extends_test.go
  29. +2
    -2
      tag_version_test.go
  30. +0
    -1
      test_mssql.sh
  31. +0
    -1
      test_mssql_cache.sh
  32. +0
    -1
      test_mymysql.sh
  33. +0
    -1
      test_mymysql_cache.sh
  34. +0
    -1
      test_mysql.sh
  35. +0
    -1
      test_mysql_cache.sh
  36. +0
    -1
      test_postgres.sh
  37. +0
    -1
      test_postgres_cache.sh
  38. +0
    -1
      test_sqlite.sh
  39. +0
    -1
      test_sqlite_cache.sh
  40. +0
    -1
      test_tidb.sh
  41. +11
    -11
      types_test.go

+ 0
- 61
.circleci/config.yml View File

@@ -1,61 +0,0 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.10

- image: circleci/mysql:5.7
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_DATABASE: xorm_test
MYSQL_HOST: 127.0.0.1
MYSQL_ROOT_HOST: '%'
MYSQL_USER: root

# CircleCI PostgreSQL images available at: https://hub.docker.com/r/circleci/postgres/
- image: circleci/postgres:9.6.2-alpine
environment:
POSTGRES_USER: circleci
POSTGRES_DB: xorm_test

- image: microsoft/mssql-server-linux:latest
environment:
ACCEPT_EULA: Y
SA_PASSWORD: yourStrong(!)Password
MSSQL_PID: Developer

- image: pingcap/tidb:v2.1.2

working_directory: /go/src/github.com/go-xorm/xorm
steps:
- checkout

- run: go get -t -d -v ./...
- run: go get -u xorm.io/core
- run: go get -u xorm.io/builder
- run: GO111MODULE=off go build -v
- run: GO111MODULE=on go build -v

- run: go get -u github.com/wadey/gocovmerge

- run: go test -v -race -db="sqlite3" -conn_str="./test.db" -coverprofile=coverage1-1.txt -covermode=atomic
- run: go test -v -race -db="sqlite3" -conn_str="./test.db" -cache=true -coverprofile=coverage1-2.txt -covermode=atomic
- run: go test -v -race -db="mysql" -conn_str="root:@/xorm_test" -coverprofile=coverage2-1.txt -covermode=atomic
- run: go test -v -race -db="mysql" -conn_str="root:@/xorm_test" -cache=true -coverprofile=coverage2-2.txt -covermode=atomic
- run: go test -v -race -db="mymysql" -conn_str="xorm_test/root/" -coverprofile=coverage3-1.txt -covermode=atomic
- run: go test -v -race -db="mymysql" -conn_str="xorm_test/root/" -cache=true -coverprofile=coverage3-2.txt -covermode=atomic
- run: go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -coverprofile=coverage4-1.txt -covermode=atomic
- run: go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic
- run: go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic
- run: go test -v -race -db="postgres" -conn_str="dbname=xorm_test sslmode=disable" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic
- run: go test -v -race -db="mssql" -conn_str="server=localhost;user id=sa;password=yourStrong(!)Password;database=xorm_test" -coverprofile=coverage6-1.txt -covermode=atomic
- run: go test -v -race -db="mssql" -conn_str="server=localhost;user id=sa;password=yourStrong(!)Password;database=xorm_test" -cache=true -coverprofile=coverage6-2.txt -covermode=atomic
- run: go test -v -race -db="mysql" -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true -coverprofile=coverage7-1.txt -covermode=atomic
- run: go test -v -race -db="mysql" -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true -cache=true -coverprofile=coverage7-2.txt -covermode=atomic
- run: gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt coverage7-1.txt coverage7-2.txt > coverage.txt

- run: bash <(curl -s https://codecov.io/bash)

+ 216
- 24
.drone.yml View File

@@ -3,7 +3,6 @@ kind: pipeline
name: testing
steps:
- name: test-vet
pull: default
image: golang:1.12
environment:
GO111MODULE: "on"
@@ -16,44 +15,106 @@ steps:
- pull_request

- name: test-sqlite
pull: default
image: golang:1.12
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_CACHE_ENABLE: false
commands:
- make test-sqlite
when:
event:
- push
- pull_request

- name: test-sqlite-cache
image: golang:1.12
depends_on:
- test-sqlite
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_CACHE_ENABLE: true
commands:
- "go test -v -race -db=\"sqlite3\" -conn_str=\"./test.db\" -coverprofile=coverage1-1.txt -covermode=atomic"
- "go test -v -race -db=\"sqlite3\" -conn_str=\"./test.db\" -cache=true -coverprofile=coverage1-2.txt -covermode=atomic"
- make test-sqlite
when:
event:
- push
- pull_request

- name: test-mysql
pull: default
image: golang:1.12
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_MYSQL_HOST: mysql
TEST_MYSQL_CHARSET: utf8
TEST_MYSQL_DBNAME: xorm_test
TEST_MYSQL_USERNAME: root
TEST_MYSQL_PASSWORD:
TEST_CACHE_ENABLE: false
commands:
- "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test\" -coverprofile=coverage2-1.txt -covermode=atomic"
- "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test\" -cache=true -coverprofile=coverage2-2.txt -covermode=atomic"
- make test-mysql
when:
event:
- push
- pull_request

- name: test-mysql-utf8mb4
pull: default
- name: test-mysql-cache
image: golang:1.12
depends_on:
- test-mysql
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_MYSQL_HOST: mysql
TEST_MYSQL_CHARSET: utf8
TEST_MYSQL_DBNAME: xorm_test
TEST_MYSQL_USERNAME: root
TEST_MYSQL_PASSWORD:
TEST_CACHE_ENABLE: true
commands:
- "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test?charset=utf8mb4\" -coverprofile=coverage2.1-1.txt -covermode=atomic"
- "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(mysql)/xorm_test?charset=utf8mb4\" -cache=true -coverprofile=coverage2.1-2.txt -covermode=atomic"
- make test-mysql
when:
event:
- push
- pull_request

- name: test-mysql-utf8mb4
image: golang:1.12
depends_on:
- test-mysql-cache
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_MYSQL_HOST: mysql
TEST_MYSQL_CHARSET: utf8mb4
TEST_MYSQL_DBNAME: xorm_test
TEST_MYSQL_USERNAME: root
TEST_MYSQL_PASSWORD:
TEST_CACHE_ENABLE: false
commands:
- make test-mysql
when:
event:
- push
- pull_request

- name: test-mysql-utf8mb4-cache
image: golang:1.12
depends_on:
- test-mysql-utf8mb4
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_MYSQL_HOST: mysql
TEST_MYSQL_CHARSET: utf8mb4
TEST_MYSQL_DBNAME: xorm_test
TEST_MYSQL_USERNAME: root
TEST_MYSQL_PASSWORD:
TEST_CACHE_ENABLE: true
commands:
- make test-mysql
when:
event:
- push
@@ -63,13 +124,37 @@ steps:
pull: default
image: golang:1.12
depends_on:
- test-mysql-utf8mb4
- test-mysql-utf8mb4-cache
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_MYSQL_HOST: mysql:3306
TEST_MYSQL_DBNAME: xorm_test
TEST_MYSQL_USERNAME: root
TEST_MYSQL_PASSWORD:
TEST_CACHE_ENABLE: false
commands:
- "go test -v -race -db=\"mymysql\" -conn_str=\"tcp:mysql:3306*xorm_test/root/\" -coverprofile=coverage3-1.txt -covermode=atomic"
- "go test -v -race -db=\"mymysql\" -conn_str=\"tcp:mysql:3306*xorm_test/root/\" -cache=true -coverprofile=coverage3-2.txt -covermode=atomic"
- make test-mymysql
when:
event:
- push
- pull_request

- name: test-mymysql-cache
pull: default
image: golang:1.12
depends_on:
- test-mymysql
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_MYSQL_HOST: mysql:3306
TEST_MYSQL_DBNAME: xorm_test
TEST_MYSQL_USERNAME: root
TEST_MYSQL_PASSWORD:
TEST_CACHE_ENABLE: true
commands:
- make test-mymysql
when:
event:
- push
@@ -81,9 +166,33 @@ steps:
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_PGSQL_HOST: pgsql
TEST_PGSQL_DBNAME: xorm_test
TEST_PGSQL_USERNAME: postgres
TEST_PGSQL_PASSWORD: postgres
TEST_CACHE_ENABLE: false
commands:
- "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:postgres@pgsql/xorm_test?sslmode=disable\" -coverprofile=coverage4-1.txt -covermode=atomic"
- "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:postgres@pgsql/xorm_test?sslmode=disable\" -cache=true -coverprofile=coverage4-2.txt -covermode=atomic"
- make test-postgres
when:
event:
- push
- pull_request

- name: test-postgres-cache
pull: default
image: golang:1.12
depends_on:
- test-postgres
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_PGSQL_HOST: pgsql
TEST_PGSQL_DBNAME: xorm_test
TEST_PGSQL_USERNAME: postgres
TEST_PGSQL_PASSWORD: postgres
TEST_CACHE_ENABLE: true
commands:
- make test-postgres
when:
event:
- push
@@ -95,9 +204,37 @@ steps:
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_PGSQL_HOST: pgsql
TEST_PGSQL_SCHEMA: xorm
TEST_PGSQL_DBNAME: xorm_test
TEST_PGSQL_USERNAME: postgres
TEST_PGSQL_PASSWORD: postgres
TEST_CACHE_ENABLE: false
SCHEMA: xorm
commands:
- make test-postgres
when:
event:
- push
- pull_request

- name: test-postgres-schema-cache
pull: default
image: golang:1.12
depends_on:
- test-postgres-schema
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_PGSQL_HOST: pgsql
TEST_PGSQL_SCHEMA: xorm
TEST_PGSQL_DBNAME: xorm_test
TEST_PGSQL_USERNAME: postgres
TEST_PGSQL_PASSWORD: postgres
TEST_CACHE_ENABLE: true
SCHEMA: xorm
commands:
- "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:postgres@pgsql/xorm_test?sslmode=disable\" -schema=xorm -coverprofile=coverage5-1.txt -covermode=atomic"
- "go test -v -race -db=\"postgres\" -conn_str=\"postgres://postgres:postgres@pgsql/xorm_test?sslmode=disable\" -schema=xorm -cache=true -coverprofile=coverage5-2.txt -covermode=atomic"
- make test-postgres
when:
event:
- push
@@ -109,9 +246,33 @@ steps:
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_MSSQL_HOST: mssql
TEST_MSSQL_DBNAME: xorm_test
TEST_MSSQL_USERNAME: sa
TEST_MSSQL_PASSWORD: "yourStrong(!)Password"
TEST_CACHE_ENABLE: false
commands:
- make test-mssql
when:
event:
- push
- pull_request

- name: test-mssql-cache
pull: default
image: golang:1.12
depends_on:
- test-mssql
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_MSSQL_HOST: mssql
TEST_MSSQL_DBNAME: xorm_test
TEST_MSSQL_USERNAME: sa
TEST_MSSQL_PASSWORD: "yourStrong(!)Password"
TEST_CACHE_ENABLE: true
commands:
- "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -coverprofile=coverage6-1.txt -covermode=atomic"
- "go test -v -race -db=\"mssql\" -conn_str=\"server=mssql;user id=sa;password=yourStrong(!)Password;database=xorm_test\" -cache=true -coverprofile=coverage6-2.txt -covermode=atomic"
- make test-mssql
when:
event:
- push
@@ -123,9 +284,33 @@ steps:
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_TIDB_HOST: "tidb:4000"
TEST_TIDB_DBNAME: xorm_test
TEST_TIDB_USERNAME: root
TEST_TIDB_PASSWORD:
TEST_CACHE_ENABLE: false
commands:
- make test-tidb
when:
event:
- push
- pull_request

- name: test-tidb-cache
pull: default
image: golang:1.12
depends_on:
- test-tidb
environment:
GO111MODULE: "on"
GOPROXY: "https://goproxy.cn"
TEST_TIDB_HOST: "tidb:4000"
TEST_TIDB_DBNAME: xorm_test
TEST_TIDB_USERNAME: root
TEST_TIDB_PASSWORD:
TEST_CACHE_ENABLE: true
commands:
- "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(tidb:4000)/xorm_test\" -ignore_select_update=true -coverprofile=coverage7-1.txt -covermode=atomic"
- "go test -v -race -db=\"mysql\" -conn_str=\"root:@tcp(tidb:4000)/xorm_test\" -ignore_select_update=true -cache=true -coverprofile=coverage7-2.txt -covermode=atomic"
- make test-tidb
when:
event:
- push
@@ -140,16 +325,23 @@ steps:
depends_on:
- test-vet
- test-sqlite
- test-sqlite-cache
- test-mysql
- test-mysql-cache
- test-mysql-utf8mb4
- test-mysql-utf8mb4-cache
- test-mymysql
- test-mymysql-cache
- test-postgres
- test-postgres-cache
- test-postgres-schema
- test-postgres-schema-cache
- test-mssql
- test-mssql-cache
- test-tidb
- test-tidb-cache
commands:
- go get github.com/wadey/gocovmerge
- gocovmerge coverage1-1.txt coverage1-2.txt coverage2-1.txt coverage2-2.txt coverage2.1-1.txt coverage2.1-2.txt coverage3-1.txt coverage3-2.txt coverage4-1.txt coverage4-2.txt coverage5-1.txt coverage5-2.txt coverage6-1.txt coverage6-2.txt coverage7-1.txt coverage7-2.txt > coverage.txt
- make coverage
when:
event:
- push


+ 25
- 0
.revive.toml View File

@@ -0,0 +1,25 @@
ignoreGeneratedHeader = false
severity = "warning"
confidence = 0.8
errorCode = 1
warningCode = 1

[rule.blank-imports]
[rule.context-as-argument]
[rule.context-keys-type]
[rule.dot-imports]
[rule.error-return]
[rule.error-strings]
[rule.error-naming]
[rule.exported]
[rule.if-return]
[rule.increment-decrement]
[rule.var-naming]
[rule.var-declaration]
[rule.package-comments]
[rule.range]
[rule.receiver-naming]
[rule.time-naming]
[rule.unexported-return]
[rule.indent-error-flow]
[rule.errorf]

+ 190
- 0
Makefile View File

@@ -0,0 +1,190 @@
IMPORT := xorm.io/xorm
export GO111MODULE=on

GO ?= go
GOFMT ?= gofmt -s
TAGS ?=
SED_INPLACE := sed -i

GOFILES := $(shell find . -name "*.go" -type f)

PACKAGES ?= $(shell GO111MODULE=on $(GO) list ./...)

TEST_MSSQL_HOST ?= mssql:1433
TEST_MSSQL_DBNAME ?= gitea
TEST_MSSQL_USERNAME ?= sa
TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1

TEST_MYSQL_HOST ?= mysql:3306
TEST_MYSQL_CHARSET ?= utf8
TEST_MYSQL_DBNAME ?= xorm_test
TEST_MYSQL_USERNAME ?= root
TEST_MYSQL_PASSWORD ?=

TEST_PGSQL_HOST ?= pgsql:5432
TEST_PGSQL_SCHEMA ?=
TEST_PGSQL_DBNAME ?= xorm_test
TEST_PGSQL_USERNAME ?= postgres
TEST_PGSQL_PASSWORD ?= mysecretpassword

TEST_TIDB_HOST ?= tidb:4000
TEST_TIDB_DBNAME ?= xorm_test
TEST_TIDB_USERNAME ?= root
TEST_TIDB_PASSWORD ?=

TEST_CACHE_ENABLE ?= false

.PHONY: all
all: build

.PHONY: build
build: go-check $(GO_SOURCES)
$(GO) build

.PHONY: clean
clean:
$(GO) clean -i ./...
rm -rf *.sql *.log test.db *coverage.out coverage.all

.PHONY: coverage
coverage:
@hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/wadey/gocovmerge; \
fi
gocovmerge $(shell find . -type f -name "coverage.out") > coverage.all;\

.PHONY: fmt
fmt:
$(GOFMT) -w $(GOFILES)

.PHONY: fmt-check
fmt-check:
# get all go files and run go fmt on them
@diff=$$($(GOFMT) -d $(GOFILES)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
exit 1; \
fi;

.PHONY: go-check
go-check:
$(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?\s' | tr '.' ' ');))
@if [ "$(GO_VERSION)" -lt "001011000" ]; then \
echo "Gitea requires Go 1.11.0 or greater to build. You can get it at https://golang.org/dl/"; \
exit 1; \
fi

.PHONY: help
help:
@echo "Make Routines:"
@echo " - equivalent to \"build\""
@echo " - build creates the entire project"
@echo " - clean delete integration files and build files but not css and js files"
@echo " - fmt format the code"
@echo " - lint run code linter revive"
@echo " - misspell check if a word is written wrong"
@echo " - test run default unit test"
@echo " - test-sqlite run unit test for sqlite"
@echo " - vet examines Go source code and reports suspicious constructs"

.PHONY: lint
lint: revive

.PHONY: revive
revive:
@hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/mgechev/revive; \
fi
revive -config .revive.toml -exclude=./vendor/... ./... || exit 1

.PHONY: misspell
misspell:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -w -i unknwon $(GOFILES)

.PHONY: misspell-check
misspell-check:
@hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
$(GO) get -u github.com/client9/misspell/cmd/misspell; \
fi
misspell -error -i unknwon,destory $(GOFILES)

.PHONY: test
test: test-sqlite

.PNONY: test-mssql
test-mssql: go-check
$(GO) test -race -db=mssql -cache=$(TEST_CACHE_ENABLE) \
-conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \
-coverprofile=mssql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PNONY: test-mssql\#%
test-mssql\#%: go-check
$(GO) test -race -run $* -db=mssql -cache=$(TEST_CACHE_ENABLE) \
-conn_str="server=$(TEST_MSSQL_HOST);user id=$(TEST_MSSQL_USERNAME);password=$(TEST_MSSQL_PASSWORD);database=$(TEST_MSSQL_DBNAME)" \
-coverprofile=mssql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PNONY: test-mymysql
test-mymysql: go-check
$(GO) test -race -db=mymysql -cache=$(TEST_CACHE_ENABLE) \
-conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \
-coverprofile=mymysql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PNONY: test-mymysql\#%
test-mymysql\#%: go-check
$(GO) test -race -run $* -db=mymysql -cache=$(TEST_CACHE_ENABLE) \
-conn_str="tcp:$(TEST_MYSQL_HOST)*$(TEST_MYSQL_DBNAME)/$(TEST_MYSQL_USERNAME)/$(TEST_MYSQL_PASSWORD)" \
-coverprofile=mymysql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PNONY: test-mysql
test-mysql: go-check
$(GO) test -race -db=mysql -cache=$(TEST_CACHE_ENABLE) \
-conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \
-coverprofile=mysql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PHONY: test-mysql\#%
test-mysql\#%: go-check
$(GO) test -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) \
-conn_str="$(TEST_MYSQL_USERNAME):$(TEST_MYSQL_PASSWORD)@tcp($(TEST_MYSQL_HOST))/$(TEST_MYSQL_DBNAME)?charset=$(TEST_MYSQL_CHARSET)" \
-coverprofile=mysql.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PNONY: test-postgres
test-postgres: go-check
$(GO) test -race -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
-conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \
-coverprofile=postgres.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PHONY: test-postgres\#%
test-postgres\#%: go-check
$(GO) test -race -run $* -db=postgres -schema='$(TEST_PGSQL_SCHEMA)' -cache=$(TEST_CACHE_ENABLE) \
-conn_str="postgres://$(TEST_PGSQL_USERNAME):$(TEST_PGSQL_PASSWORD)@$(TEST_PGSQL_HOST)/$(TEST_PGSQL_DBNAME)?sslmode=disable" \
-coverprofile=postgres.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PHONY: test-sqlite
test-sqlite: go-check
$(GO) test -race -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
-coverprofile=sqlite.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PHONY: test-sqlite\#%
test-sqlite\#%: go-check
$(GO) test -race -run $* -cache=$(TEST_CACHE_ENABLE) -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \
-coverprofile=sqlite.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PNONY: test-tidb
test-tidb: go-check
$(GO) test -race -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
-conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \
-coverprofile=tidb.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PHONY: test-tidb\#%
test-tidb\#%: go-check
$(GO) test -race -run $* -db=mysql -cache=$(TEST_CACHE_ENABLE) -ignore_select_update=true \
-conn_str="$(TEST_TIDB_USERNAME):$(TEST_TIDB_PASSWORD)@tcp($(TEST_TIDB_HOST))/$(TEST_TIDB_DBNAME)" \
-coverprofile=tidb.$(TEST_CACHE_ENABLE).coverage.out -covermode=atomic

.PHONY: vet
vet:
$(GO) vet $(PACKAGES)

+ 1
- 1
cache_lru_test.go View File

@@ -7,8 +7,8 @@ package xorm
import (
"testing"

"xorm.io/core"
"github.com/stretchr/testify/assert"
"xorm.io/core"
)

func TestLRUCache(t *testing.T) {


+ 2
- 2
cache_memory_store_test.go View File

@@ -25,12 +25,12 @@ func TestMemoryStore(t *testing.T) {
assert.EqualValues(t, v, val)
}

for k, _ := range kvs {
for k := range kvs {
err := store.Del(k)
assert.NoError(t, err)
}

for k, _ := range kvs {
for k := range kvs {
_, err := store.Get(k)
assert.EqualValues(t, ErrNotExist, err)
}


+ 3
- 3
engine.go View File

@@ -838,7 +838,7 @@ func (engine *Engine) Having(conditions string) *Session {
return session.Having(conditions)
}

// UnMapType removes the datbase mapper of a type
// UnMapType removes the database mapper of a type
func (engine *Engine) UnMapType(t reflect.Type) {
engine.mutex.Lock()
defer engine.mutex.Unlock()
@@ -987,11 +987,11 @@ func (engine *Engine) mapType(v reflect.Value) (*core.Table, error) {

pStart := strings.Index(k, "(")
if pStart == 0 {
return nil, errors.New("( could not be the first charactor")
return nil, errors.New("( could not be the first character")
}
if pStart > -1 {
if !strings.HasSuffix(k, ")") {
return nil, fmt.Errorf("field %s tag %s cannot match ) charactor", col.FieldName, key)
return nil, fmt.Errorf("field %s tag %s cannot match ) character", col.FieldName, key)
}

ctx.tagName = k[:pStart]


examples/cache.go → examples/cache/cache.go View File


examples/cachegoroutine.go → examples/cache_gorountine/cache_goroutine.go View File


examples/conversion.go → examples/conversion/conversion.go View File


examples/derive.go → examples/derive/derive.go View File


examples/find.go → examples/find/find.go View File

@@ -5,8 +5,8 @@ import (
"os"
"time"

_ "github.com/mattn/go-sqlite3"
"xorm.io/xorm"
_ "github.com/mattn/go-sqlite3"
)

// User describes a user

examples/goroutine.go → examples/goroutine/goroutine.go View File


examples/singlemapping.go → examples/mapping/single_mapping.go View File


examples/maxconnect.go → examples/max_connect/max_connect.go View File


examples/sync.go → examples/sync/sync.go View File


examples/tables.go → examples/tables/tables.go View File


+ 1
- 1
migrate/migrate_test.go View File

@@ -6,9 +6,9 @@ import (
"os"
"testing"

"xorm.io/xorm"
_ "github.com/mattn/go-sqlite3"
"github.com/stretchr/testify/assert"
"xorm.io/xorm"
)

type Person struct {


+ 1
- 1
session_cond_test.go View File

@@ -9,8 +9,8 @@ import (
"fmt"
"testing"

"xorm.io/builder"
"github.com/stretchr/testify/assert"
"xorm.io/builder"
)

func TestBuilder(t *testing.T) {


+ 1
- 1
session_delete_test.go View File

@@ -8,8 +8,8 @@ import (
"testing"
"time"

"xorm.io/core"
"github.com/stretchr/testify/assert"
"xorm.io/core"
)

func TestDelete(t *testing.T) {


+ 1
- 1
session_find_test.go View File

@@ -10,8 +10,8 @@ import (
"testing"
"time"

"xorm.io/core"
"github.com/stretchr/testify/assert"
"xorm.io/core"
)

func TestJoinLimit(t *testing.T) {


+ 13
- 13
session_insert_test.go View File

@@ -553,10 +553,10 @@ func TestInsertMulti2(t *testing.T) {
assert.EqualValues(t, len(users), cnt)

users2 := []*Userinfo{
&Userinfo{Username: "1xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
&Userinfo{Username: "1xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
&Userinfo{Username: "1xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
&Userinfo{Username: "1xlw22", Departname: "dev", Alias: "lunny3", Created: time.Now()},
{Username: "1xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
{Username: "1xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
{Username: "1xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
{Username: "1xlw22", Departname: "dev", Alias: "lunny3", Created: time.Now()},
}

cnt, err = testEngine.Insert(&users2)
@@ -646,10 +646,10 @@ func TestInsertMulti3(t *testing.T) {
assert.EqualValues(t, len(users), cnt)

users2 := []*MyUserinfo{
&MyUserinfo{Username: "1xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
&MyUserinfo{Username: "1xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
&MyUserinfo{Username: "1xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
&MyUserinfo{Username: "1xlw22", Departname: "dev", Alias: "lunny3", Created: time.Now()},
{Username: "1xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
{Username: "1xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
{Username: "1xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
{Username: "1xlw22", Departname: "dev", Alias: "lunny3", Created: time.Now()},
}

cnt, err = testEngine.Insert(&users2)
@@ -691,10 +691,10 @@ func TestInsertMulti4(t *testing.T) {
assert.EqualValues(t, len(users), cnt)

users2 := []*MyUserinfo2{
&MyUserinfo2{Username: "1xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
&MyUserinfo2{Username: "1xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
&MyUserinfo2{Username: "1xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
&MyUserinfo2{Username: "1xlw22", Departname: "dev", Alias: "lunny3", Created: time.Now()},
{Username: "1xlw", Departname: "dev", Alias: "lunny2", Created: time.Now()},
{Username: "1xlw2", Departname: "dev", Alias: "lunny3", Created: time.Now()},
{Username: "1xlw11", Departname: "dev", Alias: "lunny2", Created: time.Now()},
{Username: "1xlw22", Departname: "dev", Alias: "lunny3", Created: time.Now()},
}

cnt, err = testEngine.Insert(&users2)
@@ -1083,7 +1083,7 @@ func TestInsertTwice(t *testing.T) {

var sliceA []InsertStructA // sliceA is empty
sliceB := []InsertStructB{
InsertStructB{
{
FieldB: 1,
},
}


+ 1
- 1
session_pk_test.go View File

@@ -9,8 +9,8 @@ import (
"testing"
"time"

"xorm.io/core"
"github.com/stretchr/testify/assert"
"xorm.io/core"
)

type IntId struct {


+ 1
- 1
session_stats_test.go View File

@@ -9,8 +9,8 @@ import (
"strconv"
"testing"

"xorm.io/builder"
"github.com/stretchr/testify/assert"
"xorm.io/builder"
)

func isFloatEq(i, j float64, precision int) bool {


+ 1
- 1
session_tx_test.go View File

@@ -9,8 +9,8 @@ import (
"testing"
"time"

"xorm.io/core"
"github.com/stretchr/testify/assert"
"xorm.io/core"
)

func TestTransaction(t *testing.T) {


+ 3
- 3
session_update_test.go View File

@@ -407,7 +407,7 @@ func TestUpdate1(t *testing.T) {
}

if cnt != 1 {
err = errors.New(fmt.Sprintf("insert not returned 1 but %d", cnt))
err = fmt.Errorf("insert not returned 1 but %d", cnt)
t.Error(err)
panic(err)
}
@@ -745,7 +745,7 @@ func TestUpdateSameMapper(t *testing.T) {
assert.NoError(t, err)

if cnt != 1 {
err = errors.New(fmt.Sprintf("insert not returned 1 but %d", cnt))
err = fmt.Errorf("insert not returned 1 but %d", cnt)
t.Error(err)
panic(err)
}
@@ -861,7 +861,7 @@ func TestUseBool(t *testing.T) {
var fNumber int64
for _, u := range users {
if u.IsMan == false {
fNumber += 1
fNumber++
}
}



+ 1
- 1
tag.go View File

@@ -81,7 +81,7 @@ func OnlyToDBTagHandler(ctx *tagContext) error {
return nil
}

// PKTagHandler decribes primary key tag handler
// PKTagHandler describes primary key tag handler
func PKTagHandler(ctx *tagContext) error {
ctx.col.IsPrimaryKey = true
ctx.col.Nullable = false


+ 1
- 1
tag_extends_test.go View File

@@ -10,8 +10,8 @@ import (
"testing"
"time"

"xorm.io/core"
"github.com/stretchr/testify/assert"
"xorm.io/core"
)

type tempUser struct {


+ 2
- 2
tag_version_test.go View File

@@ -56,7 +56,7 @@ func TestVersion1(t *testing.T) {
}

if !has {
t.Error(errors.New(fmt.Sprintf("no version id is %v", ver.Id)))
t.Error(fmt.Errorf("no version id is %v", ver.Id))
panic(err)
}
fmt.Println(newVer)
@@ -170,7 +170,7 @@ func TestVersion3(t *testing.T) {
}

if !has {
t.Error(errors.New(fmt.Sprintf("no version id is %v", ver.Id)))
t.Error(fmt.Errorf("no version id is %v", ver.Id))
panic(err)
}
fmt.Println(newVer)


+ 0
- 1
test_mssql.sh View File

@@ -1 +0,0 @@
go test -db=mssql -conn_str="server=localhost;user id=sa;password=yourStrong(!)Password;database=xorm_test"

+ 0
- 1
test_mssql_cache.sh View File

@@ -1 +0,0 @@
go test -db=mssql -conn_str="server=192.168.1.58;user id=sa;password=123456;database=xorm_test" -cache=true

+ 0
- 1
test_mymysql.sh View File

@@ -1 +0,0 @@
go test -db=mymysql -conn_str="xorm_test/root/"

+ 0
- 1
test_mymysql_cache.sh View File

@@ -1 +0,0 @@
go test -db=mymysql -conn_str="xorm_test/root/" -cache=true

+ 0
- 1
test_mysql.sh View File

@@ -1 +0,0 @@
go test -db=mysql -conn_str="root:@/xorm_test"

+ 0
- 1
test_mysql_cache.sh View File

@@ -1 +0,0 @@
go test -db=mysql -conn_str="root:@/xorm_test" -cache=true

+ 0
- 1
test_postgres.sh View File

@@ -1 +0,0 @@
go test -db=postgres -conn_str="dbname=xorm_test sslmode=disable"

+ 0
- 1
test_postgres_cache.sh View File

@@ -1 +0,0 @@
go test -db=postgres -conn_str="dbname=xorm_test sslmode=disable" -cache=true

+ 0
- 1
test_sqlite.sh View File

@@ -1 +0,0 @@
go test -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc"

+ 0
- 1
test_sqlite_cache.sh View File

@@ -1 +0,0 @@
go test -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" -cache=true

+ 0
- 1
test_tidb.sh View File

@@ -1 +0,0 @@
go test -db=mysql -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true

+ 11
- 11
types_test.go View File

@@ -9,8 +9,8 @@ import (
"fmt"
"testing"

"xorm.io/core"
"github.com/stretchr/testify/assert"
"xorm.io/core"
)

func TestArrayField(t *testing.T) {
@@ -267,14 +267,14 @@ type Status struct {
}

var (
_ core.Conversion = &Status{}
Registed Status = Status{"Registed", "white"}
Approved Status = Status{"Approved", "green"}
Removed Status = Status{"Removed", "red"}
Statuses map[string]Status = map[string]Status{
Registed.Name: Registed,
Approved.Name: Approved,
Removed.Name: Removed,
_ core.Conversion = &Status{}
Registered Status = Status{"Registered", "white"}
Approved Status = Status{"Approved", "green"}
Removed Status = Status{"Removed", "red"}
Statuses map[string]Status = map[string]Status{
Registered.Name: Registered,
Approved.Name: Approved,
Removed.Name: Removed,
}
)

@@ -318,7 +318,7 @@ func TestCustomType2(t *testing.T) {
assert.NoError(t, err)
}

cnt, err := session.Insert(&UserCus{1, "xlw", Registed})
cnt, err := session.Insert(&UserCus{1, "xlw", Registered})
assert.NoError(t, err)
assert.EqualValues(t, 1, cnt)

@@ -335,7 +335,7 @@ func TestCustomType2(t *testing.T) {
fmt.Println(user)

users := make([]UserCus, 0)
err = testEngine.Where("`"+testEngine.GetColumnMapper().Obj2Table("Status")+"` = ?", "Registed").Find(&users)
err = testEngine.Where("`"+testEngine.GetColumnMapper().Obj2Table("Status")+"` = ?", "Registered").Find(&users)
assert.NoError(t, err)
assert.EqualValues(t, 1, len(users))



Loading…
Cancel
Save