From 22aef2cd3285c77bad9d6465303160530a0dae85 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 21 Feb 2020 01:38:47 +0000 Subject: [PATCH] Add makefile (#1531) Fix drone Fix ci Add deps Improve drone Fix envs Add makefile Reviewed-on: https://gitea.com/xorm/xorm/pulls/1531 --- .circleci/config.yml | 61 ----- .drone.yml | 240 ++++++++++++++++-- .revive.toml | 25 ++ Makefile | 190 ++++++++++++++ cache_lru_test.go | 2 +- cache_memory_store_test.go | 4 +- engine.go | 6 +- examples/{ => cache}/cache.go | 2 +- .../cache_goroutine.go} | 2 +- examples/{ => conversion}/conversion.go | 2 +- examples/{ => derive}/derive.go | 2 +- examples/{ => find}/find.go | 2 +- examples/{ => goroutine}/goroutine.go | 2 +- .../single_mapping.go} | 2 +- .../max_connect.go} | 2 +- examples/{ => sync}/sync.go | 2 +- examples/{ => tables}/tables.go | 2 +- migrate/migrate_test.go | 2 +- session_cond_test.go | 2 +- session_delete_test.go | 2 +- session_find_test.go | 2 +- session_insert_test.go | 26 +- session_pk_test.go | 2 +- session_stats_test.go | 2 +- session_tx_test.go | 2 +- session_update_test.go | 6 +- tag.go | 2 +- tag_extends_test.go | 2 +- tag_version_test.go | 4 +- test_mssql.sh | 1 - test_mssql_cache.sh | 1 - test_mymysql.sh | 1 - test_mymysql_cache.sh | 1 - test_mysql.sh | 1 - test_mysql_cache.sh | 1 - test_postgres.sh | 1 - test_postgres_cache.sh | 1 - test_sqlite.sh | 1 - test_sqlite_cache.sh | 1 - test_tidb.sh | 1 - types_test.go | 22 +- 41 files changed, 485 insertions(+), 150 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .revive.toml create mode 100644 Makefile rename examples/{ => cache}/cache.go (100%) rename examples/{cachegoroutine.go => cache_gorountine/cache_goroutine.go} (100%) rename examples/{ => conversion}/conversion.go (100%) rename examples/{ => derive}/derive.go (100%) rename examples/{ => find}/find.go (94%) rename examples/{ => goroutine}/goroutine.go (100%) rename examples/{singlemapping.go => mapping/single_mapping.go} (100%) rename examples/{maxconnect.go => max_connect/max_connect.go} (100%) rename examples/{ => sync}/sync.go (100%) rename examples/{ => tables}/tables.go (100%) delete mode 100755 test_mssql.sh delete mode 100755 test_mssql_cache.sh delete mode 100755 test_mymysql.sh delete mode 100755 test_mymysql_cache.sh delete mode 100755 test_mysql.sh delete mode 100755 test_mysql_cache.sh delete mode 100755 test_postgres.sh delete mode 100755 test_postgres_cache.sh delete mode 100755 test_sqlite.sh delete mode 100755 test_sqlite_cache.sh delete mode 100755 test_tidb.sh diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index c8f64282e..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -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) \ No newline at end of file diff --git a/.drone.yml b/.drone.yml index a4fb812d2..65845d8c6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -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 diff --git a/.revive.toml b/.revive.toml new file mode 100644 index 000000000..64e223bbf --- /dev/null +++ b/.revive.toml @@ -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] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..d6ce23325 --- /dev/null +++ b/Makefile @@ -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) \ No newline at end of file diff --git a/cache_lru_test.go b/cache_lru_test.go index 7da36f007..06373f791 100644 --- a/cache_lru_test.go +++ b/cache_lru_test.go @@ -7,8 +7,8 @@ package xorm import ( "testing" - "xorm.io/core" "github.com/stretchr/testify/assert" + "xorm.io/core" ) func TestLRUCache(t *testing.T) { diff --git a/cache_memory_store_test.go b/cache_memory_store_test.go index fc27ae320..8e2676838 100644 --- a/cache_memory_store_test.go +++ b/cache_memory_store_test.go @@ -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) } diff --git a/engine.go b/engine.go index b76d4c6d5..21b0ec05a 100644 --- a/engine.go +++ b/engine.go @@ -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] diff --git a/examples/cache.go b/examples/cache/cache.go similarity index 100% rename from examples/cache.go rename to examples/cache/cache.go index 5ad1de1bf..ba7568133 100644 --- a/examples/cache.go +++ b/examples/cache/cache.go @@ -4,8 +4,8 @@ import ( "fmt" "os" - "xorm.io/xorm" _ "github.com/mattn/go-sqlite3" + "xorm.io/xorm" ) // User describes a user diff --git a/examples/cachegoroutine.go b/examples/cache_gorountine/cache_goroutine.go similarity index 100% rename from examples/cachegoroutine.go rename to examples/cache_gorountine/cache_goroutine.go index c8d8ee693..94b29e828 100644 --- a/examples/cachegoroutine.go +++ b/examples/cache_gorountine/cache_goroutine.go @@ -6,8 +6,8 @@ import ( "time" _ "github.com/go-sql-driver/mysql" - "xorm.io/xorm" _ "github.com/mattn/go-sqlite3" + "xorm.io/xorm" ) // User describes a user diff --git a/examples/conversion.go b/examples/conversion/conversion.go similarity index 100% rename from examples/conversion.go rename to examples/conversion/conversion.go index 62d4a86bf..9b16fdc1c 100644 --- a/examples/conversion.go +++ b/examples/conversion/conversion.go @@ -5,8 +5,8 @@ import ( "fmt" "os" - "xorm.io/xorm" _ "github.com/mattn/go-sqlite3" + "xorm.io/xorm" ) // Status describes a status diff --git a/examples/derive.go b/examples/derive/derive.go similarity index 100% rename from examples/derive.go rename to examples/derive/derive.go index 23e7f169b..ec6fe0939 100644 --- a/examples/derive.go +++ b/examples/derive/derive.go @@ -4,8 +4,8 @@ import ( "fmt" "os" - "xorm.io/xorm" _ "github.com/mattn/go-sqlite3" + "xorm.io/xorm" ) // User describes a user diff --git a/examples/find.go b/examples/find/find.go similarity index 94% rename from examples/find.go rename to examples/find/find.go index ae27a797c..9414650ec 100644 --- a/examples/find.go +++ b/examples/find/find.go @@ -5,8 +5,8 @@ import ( "os" "time" + _ "github.com/mattn/go-sqlite3" "xorm.io/xorm" - _ "github.com/mattn/go-sqlite3" ) // User describes a user diff --git a/examples/goroutine.go b/examples/goroutine/goroutine.go similarity index 100% rename from examples/goroutine.go rename to examples/goroutine/goroutine.go index d320714a2..57cb20a42 100644 --- a/examples/goroutine.go +++ b/examples/goroutine/goroutine.go @@ -6,8 +6,8 @@ import ( "runtime" _ "github.com/go-sql-driver/mysql" - "xorm.io/xorm" _ "github.com/mattn/go-sqlite3" + "xorm.io/xorm" ) // User describes a user diff --git a/examples/singlemapping.go b/examples/mapping/single_mapping.go similarity index 100% rename from examples/singlemapping.go rename to examples/mapping/single_mapping.go index 5c61448b3..28a776d01 100644 --- a/examples/singlemapping.go +++ b/examples/mapping/single_mapping.go @@ -4,8 +4,8 @@ import ( "fmt" "os" - "xorm.io/xorm" _ "github.com/mattn/go-sqlite3" + "xorm.io/xorm" ) // User describes a user diff --git a/examples/maxconnect.go b/examples/max_connect/max_connect.go similarity index 100% rename from examples/maxconnect.go rename to examples/max_connect/max_connect.go index d8d8b0d8c..42e9ce6db 100644 --- a/examples/maxconnect.go +++ b/examples/max_connect/max_connect.go @@ -6,8 +6,8 @@ import ( "runtime" _ "github.com/go-sql-driver/mysql" - "xorm.io/xorm" _ "github.com/mattn/go-sqlite3" + "xorm.io/xorm" ) // User describes a user diff --git a/examples/sync.go b/examples/sync/sync.go similarity index 100% rename from examples/sync.go rename to examples/sync/sync.go index 92647c0fc..96aa8ae7c 100644 --- a/examples/sync.go +++ b/examples/sync/sync.go @@ -4,9 +4,9 @@ import ( "fmt" _ "github.com/go-sql-driver/mysql" - "xorm.io/xorm" _ "github.com/lib/pq" _ "github.com/mattn/go-sqlite3" + "xorm.io/xorm" ) // SyncUser2 describes a user diff --git a/examples/tables.go b/examples/tables/tables.go similarity index 100% rename from examples/tables.go rename to examples/tables/tables.go index fcf492192..eb61c795d 100644 --- a/examples/tables.go +++ b/examples/tables/tables.go @@ -4,8 +4,8 @@ import ( "fmt" "os" - "xorm.io/xorm" _ "github.com/mattn/go-sqlite3" + "xorm.io/xorm" ) func main() { diff --git a/migrate/migrate_test.go b/migrate/migrate_test.go index 3a52787c8..19554f7e6 100644 --- a/migrate/migrate_test.go +++ b/migrate/migrate_test.go @@ -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 { diff --git a/session_cond_test.go b/session_cond_test.go index 106504845..865890d0c 100644 --- a/session_cond_test.go +++ b/session_cond_test.go @@ -9,8 +9,8 @@ import ( "fmt" "testing" - "xorm.io/builder" "github.com/stretchr/testify/assert" + "xorm.io/builder" ) func TestBuilder(t *testing.T) { diff --git a/session_delete_test.go b/session_delete_test.go index 5edb07185..ca0402fdb 100644 --- a/session_delete_test.go +++ b/session_delete_test.go @@ -8,8 +8,8 @@ import ( "testing" "time" - "xorm.io/core" "github.com/stretchr/testify/assert" + "xorm.io/core" ) func TestDelete(t *testing.T) { diff --git a/session_find_test.go b/session_find_test.go index f805f06e0..9cb6ec075 100644 --- a/session_find_test.go +++ b/session_find_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "xorm.io/core" "github.com/stretchr/testify/assert" + "xorm.io/core" ) func TestJoinLimit(t *testing.T) { diff --git a/session_insert_test.go b/session_insert_test.go index 9cd5b86a8..6190d18a8 100644 --- a/session_insert_test.go +++ b/session_insert_test.go @@ -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, }, } diff --git a/session_pk_test.go b/session_pk_test.go index 4c0666347..2f54b5bf7 100644 --- a/session_pk_test.go +++ b/session_pk_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "xorm.io/core" "github.com/stretchr/testify/assert" + "xorm.io/core" ) type IntId struct { diff --git a/session_stats_test.go b/session_stats_test.go index 01c76ba52..d66a7e1fe 100644 --- a/session_stats_test.go +++ b/session_stats_test.go @@ -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 { diff --git a/session_tx_test.go b/session_tx_test.go index 23e1bf288..7c66b7c7d 100644 --- a/session_tx_test.go +++ b/session_tx_test.go @@ -9,8 +9,8 @@ import ( "testing" "time" - "xorm.io/core" "github.com/stretchr/testify/assert" + "xorm.io/core" ) func TestTransaction(t *testing.T) { diff --git a/session_update_test.go b/session_update_test.go index 274a6bfa8..d646ff2db 100644 --- a/session_update_test.go +++ b/session_update_test.go @@ -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++ } } diff --git a/tag.go b/tag.go index ec8d5cf05..2add6485c 100644 --- a/tag.go +++ b/tag.go @@ -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 diff --git a/tag_extends_test.go b/tag_extends_test.go index 5a8031f01..b23b81815 100644 --- a/tag_extends_test.go +++ b/tag_extends_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "xorm.io/core" "github.com/stretchr/testify/assert" + "xorm.io/core" ) type tempUser struct { diff --git a/tag_version_test.go b/tag_version_test.go index cd6dc9350..878737c13 100644 --- a/tag_version_test.go +++ b/tag_version_test.go @@ -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) diff --git a/test_mssql.sh b/test_mssql.sh deleted file mode 100755 index 7f060cff3..000000000 --- a/test_mssql.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=mssql -conn_str="server=localhost;user id=sa;password=yourStrong(!)Password;database=xorm_test" \ No newline at end of file diff --git a/test_mssql_cache.sh b/test_mssql_cache.sh deleted file mode 100755 index 76efd6ca0..000000000 --- a/test_mssql_cache.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=mssql -conn_str="server=192.168.1.58;user id=sa;password=123456;database=xorm_test" -cache=true \ No newline at end of file diff --git a/test_mymysql.sh b/test_mymysql.sh deleted file mode 100755 index f7780d14f..000000000 --- a/test_mymysql.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=mymysql -conn_str="xorm_test/root/" \ No newline at end of file diff --git a/test_mymysql_cache.sh b/test_mymysql_cache.sh deleted file mode 100755 index 0100286d6..000000000 --- a/test_mymysql_cache.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=mymysql -conn_str="xorm_test/root/" -cache=true \ No newline at end of file diff --git a/test_mysql.sh b/test_mysql.sh deleted file mode 100755 index 650e4ee17..000000000 --- a/test_mysql.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=mysql -conn_str="root:@/xorm_test" \ No newline at end of file diff --git a/test_mysql_cache.sh b/test_mysql_cache.sh deleted file mode 100755 index c542e7359..000000000 --- a/test_mysql_cache.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=mysql -conn_str="root:@/xorm_test" -cache=true \ No newline at end of file diff --git a/test_postgres.sh b/test_postgres.sh deleted file mode 100755 index dc1152e0a..000000000 --- a/test_postgres.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=postgres -conn_str="dbname=xorm_test sslmode=disable" \ No newline at end of file diff --git a/test_postgres_cache.sh b/test_postgres_cache.sh deleted file mode 100755 index 462fc948c..000000000 --- a/test_postgres_cache.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=postgres -conn_str="dbname=xorm_test sslmode=disable" -cache=true \ No newline at end of file diff --git a/test_sqlite.sh b/test_sqlite.sh deleted file mode 100755 index 6352b5cb5..000000000 --- a/test_sqlite.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" \ No newline at end of file diff --git a/test_sqlite_cache.sh b/test_sqlite_cache.sh deleted file mode 100755 index 75a054c3f..000000000 --- a/test_sqlite_cache.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=sqlite3 -conn_str="./test.db?cache=shared&mode=rwc" -cache=true \ No newline at end of file diff --git a/test_tidb.sh b/test_tidb.sh deleted file mode 100755 index 03d2d6cd8..000000000 --- a/test_tidb.sh +++ /dev/null @@ -1 +0,0 @@ -go test -db=mysql -conn_str="root:@tcp(localhost:4000)/xorm_test" -ignore_select_update=true \ No newline at end of file diff --git a/types_test.go b/types_test.go index 274609b20..c979ded4c 100644 --- a/types_test.go +++ b/types_test.go @@ -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))