diff --git a/schema/model_test.go b/schema/model_test.go index aca7e617..343e324e 100644 --- a/schema/model_test.go +++ b/schema/model_test.go @@ -18,7 +18,7 @@ type User struct { Toys []*tests.Toy `gorm:"polymorphic:Owner"` CompanyID *int Company *tests.Company - ManagerID *int + ManagerID *uint Manager *User Team []*User `gorm:"foreignkey:ManagerID"` Languages []*tests.Language `gorm:"many2many:UserSpeak"` diff --git a/schema/schema_test.go b/schema/schema_test.go index 4134c966..ce225010 100644 --- a/schema/schema_test.go +++ b/schema/schema_test.go @@ -40,7 +40,7 @@ func checkUserSchema(t *testing.T, user *schema.Schema) { {Name: "Age", DBName: "age", BindNames: []string{"Age"}, DataType: schema.Uint}, {Name: "Birthday", DBName: "birthday", BindNames: []string{"Birthday"}, DataType: schema.Time}, {Name: "CompanyID", DBName: "company_id", BindNames: []string{"CompanyID"}, DataType: schema.Int}, - {Name: "ManagerID", DBName: "manager_id", BindNames: []string{"ManagerID"}, DataType: schema.Int}, + {Name: "ManagerID", DBName: "manager_id", BindNames: []string{"ManagerID"}, DataType: schema.Uint}, {Name: "Active", DBName: "active", BindNames: []string{"Active"}, DataType: schema.Bool}, } diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..6ae3337f --- /dev/null +++ b/tests/README.md @@ -0,0 +1,10 @@ +# Test Guide + +```bash +cd tests +# prepare test databases +docker-compose up + +# run all tests +./tests_all.sh +``` diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml new file mode 100644 index 00000000..79bf5fc3 --- /dev/null +++ b/tests/docker-compose.yml @@ -0,0 +1,30 @@ +version: '3' + +services: + mysql: + image: 'mysql:latest' + ports: + - 9910:3306 + environment: + - MYSQL_DATABASE=gorm + - MYSQL_USER=gorm + - MYSQL_PASSWORD=gorm + - MYSQL_RANDOM_ROOT_PASSWORD="yes" + postgres: + image: 'postgres:latest' + ports: + - 9920:5432 + environment: + - POSTGRES_USER=gorm + - POSTGRES_DB=gorm + - POSTGRES_PASSWORD=gorm + mssql: + image: 'mcmoe/mssqldocker:latest' + ports: + - 9930:1433 + environment: + - ACCEPT_EULA=Y + - SA_PASSWORD=LoremIpsum86 + - MSSQL_DB=gorm + - MSSQL_USER=gorm + - MSSQL_PASSWORD=LoremIpsum86 diff --git a/tests/tests_all.sh b/tests/tests_all.sh new file mode 100755 index 00000000..91d415f1 --- /dev/null +++ b/tests/tests_all.sh @@ -0,0 +1,25 @@ +dialects=("postgres" "mysql" "mssql" "sqlite") + +if [[ $(pwd) == *"gorm/tests"* ]]; then + cd .. +fi + +for dialect in "${dialects[@]}" ; do + if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ] + then + if [ "$GORM_VERBOSE" = "" ] + then + cd dialects/${dialect} + DEBUG=false GORM_DIALECT=${dialect} go test -race ./... + cd ../.. + + DEBUG=false GORM_DIALECT=${dialect} go test -race ./... + else + cd dialects/${dialect} + DEBUG=false GORM_DIALECT=${dialect} go test -race ./... + cd ../.. + + DEBUG=false GORM_DIALECT=${dialect} go test -race -v ./... + fi + fi +done diff --git a/wercker.yml b/wercker.yml new file mode 100644 index 00000000..54d80be0 --- /dev/null +++ b/wercker.yml @@ -0,0 +1,132 @@ +# use the default golang container from Docker Hub +box: golang + +services: + - name: mariadb + id: mariadb:latest + env: + MYSQL_DATABASE: gorm + MYSQL_USER: gorm + MYSQL_PASSWORD: gorm + MYSQL_RANDOM_ROOT_PASSWORD: "yes" + - name: mysql + id: mysql:latest + env: + MYSQL_DATABASE: gorm + MYSQL_USER: gorm + MYSQL_PASSWORD: gorm + MYSQL_RANDOM_ROOT_PASSWORD: "yes" + - name: mysql57 + id: mysql:5.7 + env: + MYSQL_DATABASE: gorm + MYSQL_USER: gorm + MYSQL_PASSWORD: gorm + MYSQL_RANDOM_ROOT_PASSWORD: "yes" + - name: mysql56 + id: mysql:5.6 + env: + MYSQL_DATABASE: gorm + MYSQL_USER: gorm + MYSQL_PASSWORD: gorm + MYSQL_RANDOM_ROOT_PASSWORD: "yes" + - name: postgres + id: postgres:latest + env: + POSTGRES_USER: gorm + POSTGRES_PASSWORD: gorm + POSTGRES_DB: gorm + - name: postgres11 + id: postgres:11 + env: + POSTGRES_USER: gorm + POSTGRES_PASSWORD: gorm + POSTGRES_DB: gorm + - name: postgres10 + id: postgres:10 + env: + POSTGRES_USER: gorm + POSTGRES_PASSWORD: gorm + POSTGRES_DB: gorm + - name: mssql + id: mcmoe/mssqldocker:latest + env: + ACCEPT_EULA: Y + SA_PASSWORD: LoremIpsum86 + MSSQL_DB: gorm + MSSQL_USER: gorm + MSSQL_PASSWORD: LoremIpsum86 + +# The steps that will be executed in the build pipeline +build: + # The steps that will be executed on build + steps: + # Sets the go workspace and places you package + # at the right place in the workspace tree + - setup-go-workspace + + # Gets the dependencies + - script: + name: go get + code: | + cd $WERCKER_SOURCE_DIR + go version + go get -t -v ./... + + # Build the project + - script: + name: go build + code: | + go build ./... + + # Test the project + - script: + name: test sqlite + code: | + GORM_DIALECT=sqlite $GORM_VERBOSE=true ./tests/tests_all.sh + + - script: + name: test mariadb + code: | + GORM_DIALECT=mysql $GORM_VERBOSE=true GORM_DSN="gorm:gorm@tcp(mariadb:3306)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh + + - script: + name: test mysql + code: | + GORM_DIALECT=mysql $GORM_VERBOSE=true GORM_DSN="gorm:gorm@tcp(mysql:3306)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh + + - script: + name: test mysql5.7 + code: | + GORM_DIALECT=mysql $GORM_VERBOSE=true GORM_DSN="gorm:gorm@tcp(mysql57:3306)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh + + - script: + name: test mysql5.6 + code: | + GORM_DIALECT=mysql $GORM_VERBOSE=true GORM_DSN="gorm:gorm@tcp(mysql56:3306)/gorm?charset=utf8&parseTime=True" ./tests/tests_all.sh + + - script: + name: test postgres + code: | + GORM_DIALECT=postgres $GORM_VERBOSE=true GORM_DSN="host=postgres user=gorm password=gorm DB.name=gorm port=5432 sslmode=disable" ./tests/tests_all.sh + + - script: + name: test postgres11 + code: | + GORM_DIALECT=postgres $GORM_VERBOSE=true GORM_DSN="host=postgres96 user=gorm password=gorm DB.name=gorm port=5432 sslmode=disable" ./tests/tests_all.sh + + - script: + name: test postgres10 + code: | + GORM_DIALECT=postgres $GORM_VERBOSE=true GORM_DSN="host=postgres95 user=gorm password=gorm DB.name=gorm port=5432 sslmode=disable" ./tests/tests_all.sh + + - script: + name: test mssql + code: | + GORM_DIALECT=mssql $GORM_VERBOSE=true GORM_DSN="sqlserver://gorm:LoremIpsum86@mssql:1433?database=gorm" ./tests/tests_all.sh + + - script: + name: codecov + code: | + go test -race -coverprofile=coverage.txt -covermode=atomic ./... + bash <(curl -s https://codecov.io/bash)