diff --git a/.circleci/config.yml b/.circleci/config.yml index 6eceb10e0..dc2a1b6a9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,7 +3,7 @@ jobs: build: working_directory: /root docker: - - image: aarondl0/sqlboiler-test:latest + - image: aarondl0/sqlboiler-test:v3 - image: postgres:9.6 environment: @@ -13,10 +13,10 @@ jobs: environment: MYSQL_ROOT_PASSWORD: mysqlpassword -# - image: microsoft/mssql-server-linux:ctp2-0 -# environment: -# ACCEPT_EULA: 'Y' -# SA_PASSWORD: 'R@@tr@@t1234' + - image: microsoft/mssql-server-linux:2017-GDR + environment: + ACCEPT_EULA: 'Y' + SA_PASSWORD: 'Sqlboiler@1234' environment: GOPATH: /go @@ -24,140 +24,109 @@ jobs: steps: - run: - name: Add PSQL Creds + name: 'Make GOPATH' + command: mkdir -p $ROOTPATH + + - checkout: + name: 'Checkout' + path: /go/src/github.com/volatiletech/sqlboiler + + # Workaround to allow the use of the circleci local cli. + - run: + name: 'Checkout (local)' + command: | + if [ ! -z "$ROOTPATH" ]; then rmdir $ROOTPATH; ln -s /root $ROOTPATH; fi + + - run: + name: 'Add PSQL Credentials' command: | echo "*:*:*:*:psqlpassword" > /root/.pgpass chmod 600 /root/.pgpass + - run: - name: Add MySQL Creds + name: 'Add MySQL Credentials' command: | echo -e "[client]\nuser = root\npassword = mysqlpassword\nhost = localhost\nprotocol = tcp" > /root/.my.cnf chmod 600 /root/.my.cnf - run: - name: Wait for PSQL + name: 'Wait for PSQL' command: > + c=0; for i in `seq 30`; do echo "Waiting for psql" - set +o errexit - psql --host localhost --username postgres --dbname template1 -c 'select * from information_schema.tables;' > /dev/null - status=$? - set -o errexit - if [ $status -eq 0 ]; then - break - fi - if [ $i -eq 30 ]; then - echo "Failed to wait for psql" - exit 1 - fi - sleep 1 - done + psql --host localhost --username postgres --dbname template1 -c 'select * from information_schema.tables;' > /dev/null && c=0 && break || c=$? && sleep 1 + done; + exit $c - run: - name: Wait for MySQL + name: 'Wait for MySQL' command: > + c=0; for i in `seq 30`; do echo "Waiting for mysql" - set +o errexit - mysql --execute 'select * from information_schema.tables;' > /dev/null - status=$? - set -o errexit - if [ $status -eq 0 ]; then - break - fi - if [ $i -eq 30 ]; then - echo "Failed to wait for mysql" - exit 1 - fi - sleep 1 - done - -# - run: -# name: Wait for MSSQL -# command: > -# for i in `seq 30`; do -# echo "Waiting for mssql" -# set +o errexit -# sqlcmd -H localhost -U sa -P R@@tr@@t1234 -Q "select * from information_schema.tables;" > /dev/null -# status=$? -# set -o errexit -# if [ $status -eq 0 ]; then -# break -# fi -# if [ $i -eq 30 ]; then -# echo "Failed to wait for mssql" -# exit 1 -# fi -# sleep 1 -# done + mysql --execute 'select * from information_schema.tables;' > /dev/null > /dev/null && c=0 && break || c=$? && sleep 1 + done; + exit $c - run: - name: Make GOPATH - command: mkdir -p /go/src/github.com/volatiletech/sqlboiler - - - checkout: - path: /go/src/github.com/volatiletech/sqlboiler + name: Wait for MSSQL + command: > + c=0; + for i in `seq 30`; do + echo "Waiting for mssql" + sqlcmd -H localhost -U sa -P Sqlboiler@1234 -Q "select * from information_schema.tables;" > /dev/null > /dev/null && c=0 && break || c=$? && sleep 1 + done; + exit $c - run: - name: Create PSQL DB - command: | - createdb --host localhost --username postgres --owner postgres sqlboiler - psql --host localhost --username postgres --dbname sqlboiler < $ROOTPATH/testdata/postgres_test_schema.sql - - run: - name: Create MySQL DB + name: 'Download dependencies (core, driver, test, generated)' command: | - mysql --host localhost --execute 'create database sqlboiler;' - mysql --host localhost --database sqlboiler < $ROOTPATH/testdata/mysql_test_schema.sql -# - run: -# name: Create MSSQL DB -# command: | -# sqlcmd -S localhost -U sa -P R@@tr@@t1234 -Q "create database sqlboiler;" -# sqlcmd -S localhost -U sa -P R@@tr@@t1234 -d sqlboiler -i $ROOTPATH/testdata/mssql_test_schema.sql + cd $ROOTPATH; go get -v -t ./... - run: - name: Build SQLBoiler + name: 'Build SQLBoiler core and drivers' command: | - cd $ROOTPATH; go get -v -t - cd $ROOTPATH; go build -v github.com/volatiletech/sqlboiler - - - run: - name: 'Configure SQLBoiler: PSQL' - command: echo -e '[postgres]\nhost="localhost"\nport=5432\nuser="postgres"\npass="psqlpassword"\ndbname="sqlboiler"\nsslmode="disable"\n' > $ROOTPATH/sqlboiler.toml - - run: - name: 'Configure SQLBoiler: MySQL' - command: echo -e '[mysql]\nhost="localhost"\nport=3306\nuser="root"\npass="mysqlpassword"\ndbname="sqlboiler"\nsslmode="false"\n' >> $ROOTPATH/sqlboiler.toml -# - run: -# name: 'Configure SQLBoiler: MSSQL' -# command: echo -e '[mssql]\nhost="localhost"\nport=1433\nuser="sa"\npass="R@@tr@@t1234"\ndbname="sqlboiler"\nsslmode="disable"\n' >> $ROOTPATH/sqlboiler.toml + cd $ROOTPATH; make build + cd $ROOTPATH; make build-{psql,mysql,mssql} - run: - name: 'Generate: PSQL' - command: cd $ROOTPATH; ./sqlboiler -o postgres postgres - - run: - name: 'Generate: MySQL' - command: cd $ROOTPATH; ./sqlboiler -o mysql mysql -# - run: -# name: 'Generate: MSSQL' -# command: cd $ROOTPATH; ./sqlboiler -o mssql mssql + name: 'Prepare for tests' + command: | + mkdir -p $HOME/test_results - run: - name: Download generated and test deps + name: 'Tests: All (except drivers,vendor)' command: | cd $ROOTPATH - go get -v -t ./... + make test | tee $HOME/test_results/results.txt + for engine in psql mysql mssql; do + make test-user-${engine} + make test-db-${engine} + make test-generate-${engine} + # workaround to fix failing tests due to the absence of 'table_schema.sql' + if [ "${engine}" != "mssql" ]; then + make test-${engine} | tee $HOME/test_results/results.${engine}.txt + fi + done - run: - name: Run Tests + name: 'Tests: Drivers' command: | cd $ROOTPATH - #cp ./testdata/mssql_test_schema.sql mssql/tables_schema.sql - go test -v -race ./... | tee test_out.txt + for engine in psql mysql mssql; do + make driver-db-${engine} + make driver-user-${engine} + make driver-test-${engine} | tee $HOME/test_results/results.driver-${engine}.txt + done - run: - name: Convert test output to JUNIT + name: 'Tests: Convert from plain to JUnit' command: | - mkdir -p $HOME/test_results/go - cat $ROOTPATH/test_out.txt | go-junit-report > $HOME/test_results/go/out.xml + for file in $HOME/test_results/*.txt; do + cat ${file} | go-junit-report > "${file%.txt}.xml" + done - store_test_results: + name: 'Store test results' path: test_results diff --git a/Makefile b/Makefile index 12205606b..71255c8b8 100644 --- a/Makefile +++ b/Makefile @@ -3,16 +3,6 @@ # files set up with admin users) as well as the mssql db set up with # the sa / Sqlboiler@1234 credentials (see docker run below for example) -.PHONY: \ - build build-psql build-mysql build-mssql \ - tests test-psql test-mysql test-mssql \ - test-dbs test-db-psql test-db-mysql test-db-mssql \ - test-users test-user-psql test-user-mysql test-user-mssql \ - driver-tests driver-test-psql driver-test-mysql driver-test-mssql \ - driver-users driver-user-psql driver-user-mysql driver-user-mssql \ - driver-dbs driver-db-psql driver-db-mysql driver-db-mssql \ - run-mssql - USER=sqlboiler_root_user DB=sqlboiler_model_test PASS=sqlboiler @@ -22,38 +12,47 @@ DRIVER_USER=sqlboiler_driver_user DRIVER_DB=sqlboiler_driver_test # Builds all software and runs model tests +.PHONY: tests tests: test-psql test-mysql test-mssql + # Creates super users +.PHONY: test-users test-users: test-user-psql test-user-mysql test-user-mssql + # Creates databases +.PHONY: test-dbs test-dbs: test-db-psql test-db-mysql test-db-mssql # Runs tests on the drivers +.PHONY: driver-tests driver-tests: driver-test-psql driver-test-mysql driver-test-mssql + # Creates regular databases +.PHONY: driver-dbs driver-dbs: driver-db-psql driver-db-mysql driver-db-mssql + # Creates regular users with access to only one DB, may modify the DB # to ensure write access to the user +.PHONY: driver-users driver-users: driver-user-psql driver-user-mysql driver-user-mssql -run-mssql: - docker run --detach --rm --env 'ACCEPT_EULA=Y' --env 'SA_PASSWORD=Sqlboiler@1234' --publish 1433:1433 --name mssql microsoft/mssql-server-linux:2017-latest -kill-mssql: - docker rm --force mssql - # ==================================== # Building operations # ==================================== +.PHONY: build build: go build github.com/volatiletech/sqlboiler +.PHONY: build-psql build-psql: go build github.com/volatiletech/sqlboiler/drivers/sqlboiler-psql +.PHONY: build-mysql build-mysql: go build github.com/volatiletech/sqlboiler/drivers/sqlboiler-mysql +.PHONY: build-mssql build-mssql: go build github.com/volatiletech/sqlboiler/drivers/sqlboiler-mssql @@ -61,87 +60,122 @@ build-mssql: # Testing operations # ==================================== -test-psql: build build-psql - ./sqlboiler --wipe psql - go test ./models - -test-mysql: build build-mysql - ./sqlboiler --wipe mysql - go test ./models - -test-mssql: build build-mssql - ./sqlboiler --wipe mssql - go test ./models +.PHONY: test +test: + go test -v -race $(go list ./... | grep -v /drivers/ | grep -v /vendor/) +.PHONY: test-user-psql test-user-psql: # Can't use createuser because it interactively promtps for a password - psql --command "create user $(USER) with superuser password '$(PASS)';" postgres + psql --host localhost --username postgres --command "create user $(USER) with superuser password '$(PASS)';" +.PHONY: test-user-mysql test-user-mysql: - mysql --execute "create user $(USER) identified by '$(PASS)';" - mysql --execute "grant all privileges on *.* to $(USER);" + mysql --host localhost --execute "create user $(USER) identified by '$(PASS)';" + mysql --host localhost --execute "grant all privileges on *.* to $(USER);" # Must be run after a database is created +.PHONY: test-user-mssql test-user-mssql: sqlcmd -S localhost -U sa -P $(MSSQLPASS) -Q "create login $(USER) with password = '$(MSSQLPASS)';" sqlcmd -S localhost -U sa -P $(MSSQLPASS) -Q "alter server role sysadmin add member $(USER);" +.PHONY: test-db-psql test-db-psql: - env PGPASSWORD=$(PASS) dropdb --username $(USER) --if-exists $(DB) - env PGPASSWORD=$(PASS) createdb --owner $(USER) --username $(USER) $(DB) - env PGPASSWORD=$(PASS) psql --username $(USER) --file testdata/psql_test_schema.sql $(DB) + env PGPASSWORD=$(PASS) dropdb --host localhost --username $(USER) --if-exists $(DB) + env PGPASSWORD=$(PASS) createdb --host localhost --owner $(USER) --username $(USER) $(DB) + env PGPASSWORD=$(PASS) psql --host localhost --username $(USER) --file testdata/psql_test_schema.sql $(DB) +.PHONY: test-db-mysql test-db-mysql: - mysql --user $(USER) --password=$(PASS) --execute "drop database if exists $(DB);" - mysql --user $(USER) --password=$(PASS) --execute "create database $(DB);" - mysql --user $(USER) --password=$(PASS) $(DB) < testdata/mysql_test_schema.sql + mysql --host localhost --user $(USER) --password=$(PASS) --execute "drop database if exists $(DB);" + mysql --host localhost --user $(USER) --password=$(PASS) --execute "create database $(DB);" + mysql --host localhost --user $(USER) --password=$(PASS) $(DB) < testdata/mysql_test_schema.sql +.PHONY: test-db-mssql test-db-mssql: sqlcmd -S localhost -U $(USER) -P $(MSSQLPASS) -Q "drop database if exists $(DB)"; sqlcmd -S localhost -U $(USER) -P $(MSSQLPASS) -Q "create database $(DB)"; sqlcmd -S localhost -U $(USER) -P $(MSSQLPASS) -d $(DB) -i testdata/mssql_test_schema.sql +.PHONY: test-generate-psql +test-generate-psql: + printf "[psql]\nhost=\"localhost\"\nport=5432\nuser=\"%s\"\npass=\"%s\"\ndbname=\"%s\"\nsslmode=\"disable\"\n" $(USER) $(PASS) $(DB) > sqlboiler.toml + ./sqlboiler --wipe psql + +.PHONY: test-generate-mysql +test-generate-mysql: + printf "[mysql]\nhost=\"localhost\"\nport=3306\nuser=\"%s\"\npass=\"%s\"\ndbname=\"%s\"\nsslmode=\"false\"\n" $(USER) $(PASS) $(DB) > sqlboiler.toml + ./sqlboiler --wipe mysql + +.PHONY: test-generate-mssql +test-generate-mssql: + printf "[mssql]\nhost=\"localhost\"\nport=1433\nuser=\"%s\"\npass=\"%s\"\ndbname=\"%s\"\nsslmode=\"disable\"\n" $(USER) $(MSSQLPASS) $(DB) > sqlboiler.toml + ./sqlboiler --wipe mssql + +.PHONY: test-psql +test-psql: + go test -v -race ./models + +.PHONY: test-mysql +test-mysql: + go test -v -race ./models + +.PHONY: test-mssql +test-mssql: + go test -v -race ./models + # ==================================== # Driver operations # ==================================== -driver-test-psql: - cd drivers/sqlboiler-psql/driver && go test -driver-test-mysql: - go test github.com/volatiletech/sqlboiler/drivers/sqlboiler-mysql/driver -driver-test-mssql: - go test github.com/volatiletech/sqlboiler/drivers/sqlboiler-mssql/driver - +.PHONY: driver-db-psql driver-db-psql: - createdb $(DRIVER_DB) + env PGPASSWORD=$(PASS) createdb --host localhost --username $(USER) --owner $(USER) $(DRIVER_DB) +.PHONY: driver-db-mysql driver-db-mysql: - mysql --execute "create database $(DRIVER_DB);" + mysql --host localhost --user $(USER) --password=$(PASS) --execute "create database $(DRIVER_DB);" +.PHONY: driver-db-mssql driver-db-mssql: sqlcmd -S localhost -U sa -P $(MSSQLPASS) -Q "create database $(DRIVER_DB);" sqlcmd -S localhost -U sa -P $(MSSQLPASS) -d $(DRIVER_DB) -Q "exec sp_configure 'contained database authentication', 1;" sqlcmd -S localhost -U sa -P $(MSSQLPASS) -d $(DRIVER_DB) -Q "reconfigure" sqlcmd -S localhost -U sa -P $(MSSQLPASS) -d $(DRIVER_DB) -Q "alter database $(DRIVER_DB) set containment = partial;" +.PHONY: driver-user-psql driver-user-psql: - psql --command "create role $(DRIVER_USER) login nocreatedb nocreaterole nocreateuser password '$(PASS)';" $(DRIVER_DB) - psql --command "alter database $(DRIVER_DB) owner to $(DRIVER_USER);" $(DRIVER_DB) + env PGPASSWORD=$(PASS) psql --host localhost --username $(USER) --command "create role $(DRIVER_USER) login nocreatedb nocreaterole password '$(PASS)';" $(DRIVER_DB) + env PGPASSWORD=$(PASS) psql --host localhost --username $(USER) --command "alter database $(DRIVER_DB) owner to $(DRIVER_USER);" $(DRIVER_DB) +.PHONY: driver-user-mysql driver-user-mysql: - mysql --execute "create user $(DRIVER_USER) identified by '$(PASS)';" - mysql --execute "grant all privileges on $(DRIVER_DB).* to $(DRIVER_USER);" + mysql --host localhost --execute "create user $(DRIVER_USER) identified by '$(PASS)';" + mysql --host localhost --execute "grant all privileges on $(DRIVER_DB).* to $(DRIVER_USER);" +.PHONY: driver-user-mssql driver-user-mssql: sqlcmd -S localhost -U sa -P $(MSSQLPASS) -d $(DRIVER_DB) -Q "create user $(DRIVER_USER) with password = '$(MSSQLPASS)'"; sqlcmd -S localhost -U sa -P $(MSSQLPASS) -d $(DRIVER_DB) -Q "grant alter, control to $(DRIVER_USER)"; + +.PHONY: driver-test-psql +driver-test-psql: + go test -v -race github.com/volatiletech/sqlboiler/drivers/sqlboiler-psql/driver -hostname localhost -username $(DRIVER_USER) -password $(PASS) -database $(DRIVER_DB) + +.PHONY: driver-test-mysql +driver-test-mysql: + go test -v -race github.com/volatiletech/sqlboiler/drivers/sqlboiler-mysql/driver -hostname localhost -username $(DRIVER_USER) -password $(PASS) -database $(DRIVER_DB) + +.PHONY: driver-test-mssql +driver-test-mssql: + go test -v -race github.com/volatiletech/sqlboiler/drivers/sqlboiler-mssql/driver -hostname localhost -username $(DRIVER_USER) -password $(MSSQLPASS) -database $(DRIVER_DB) # ==================================== # Clean operations # ==================================== +.PHONY: clean clean: - rm ./sqlboiler - rm ./sqlboiler-psql - rm ./sqlboiler-mysql - rm ./sqlboiler-mssql + rm -f ./sqlboiler + rm -f ./sqlboiler-* diff --git a/drivers/sqlboiler-mssql/driver/mssql_test.go b/drivers/sqlboiler-mssql/driver/mssql_test.go index ad1d73872..c1c94cbad 100644 --- a/drivers/sqlboiler-mssql/driver/mssql_test.go +++ b/drivers/sqlboiler-mssql/driver/mssql_test.go @@ -35,14 +35,18 @@ import ( ) var ( - flagGolden = flag.Bool("test.golden", false, "Overwrite the golden file with the current execution results") + flagOverwriteGolden = flag.Bool("overwrite-golden", false, "Overwrite the golden file with the current execution results") + flagHostname = flag.String("hostname", "", "Connect to the server on the given host") + flagUsername = flag.String("username", "", "Username to use when connecting to server") + flagPassword = flag.String("password", "", "Password to use when connecting to server") + flagDatabase = flag.String("database", "", "The database to use") rgxKeyIDs = regexp.MustCompile(`__[A-F0-9]+$`) ) func TestDriver(t *testing.T) { out := &bytes.Buffer{} - createDB := exec.Command("sqlcmd", "-S", "localhost", "-U", "sqlboiler_driver_user", "-P", "Sqlboiler@1234", "-d", "sqlboiler_driver_test", "-b", "-i", "testdatabase.sql") + createDB := exec.Command("sqlcmd", "-S", *flagHostname, "-U", *flagUsername, "-P", *flagPassword, "-d", *flagDatabase, "-b", "-i", "testdatabase.sql") createDB.Stdout = out createDB.Stderr = out @@ -53,10 +57,10 @@ func TestDriver(t *testing.T) { t.Logf("mssql output:\n%s\n", out.Bytes()) config := drivers.Config{ - "user": "sqlboiler_driver_user", - "pass": "Sqlboiler@1234", - "dbname": "sqlboiler_driver_test", - "host": "localhost", + "user": *flagUsername, + "pass": *flagPassword, + "dbname": *flagDatabase, + "host": *flagHostname, "port": 1433, "sslmode": "disable", "schema": "dbo", @@ -80,7 +84,7 @@ func TestDriver(t *testing.T) { t.Fatal(err) } - if *flagGolden { + if *flagOverwriteGolden { if err = ioutil.WriteFile("mssql.golden.json", got, 0664); err != nil { t.Fatal(err) } diff --git a/drivers/sqlboiler-mssql/sqlboiler-mssql b/drivers/sqlboiler-mssql/sqlboiler-mssql deleted file mode 100755 index 8dc05a626..000000000 Binary files a/drivers/sqlboiler-mssql/sqlboiler-mssql and /dev/null differ diff --git a/drivers/sqlboiler-mysql/driver/mysql_test.go b/drivers/sqlboiler-mysql/driver/mysql_test.go index ba641076c..1cae74454 100644 --- a/drivers/sqlboiler-mysql/driver/mysql_test.go +++ b/drivers/sqlboiler-mysql/driver/mysql_test.go @@ -13,6 +13,7 @@ import ( "bytes" "encoding/json" "flag" + "fmt" "io/ioutil" "os/exec" "testing" @@ -21,7 +22,11 @@ import ( ) var ( - flagGolden = flag.Bool("test.golden", false, "Overwrite the golden file with the current execution results") + flagOverwriteGolden = flag.Bool("overwrite-golden", false, "Overwrite the golden file with the current execution results") + flagHostname = flag.String("hostname", "", "Connect to the server on the given host") + flagUsername = flag.String("username", "", "Username to use when connecting to server") + flagPassword = flag.String("password", "", "Password to use when connecting to server") + flagDatabase = flag.String("database", "", "The database to use") ) func TestDriver(t *testing.T) { @@ -31,7 +36,7 @@ func TestDriver(t *testing.T) { } out := &bytes.Buffer{} - createDB := exec.Command("mysql", "-u", "sqlboiler_driver_user", "-psqlboiler", "sqlboiler_driver_test") + createDB := exec.Command("mysql", "-h", *flagHostname, "-u", *flagUsername, fmt.Sprintf("-p%s", *flagPassword), *flagDatabase) createDB.Stdout = out createDB.Stderr = out createDB.Stdin = bytes.NewReader(b) @@ -43,13 +48,13 @@ func TestDriver(t *testing.T) { t.Logf("mysql output:\n%s\n", out.Bytes()) config := drivers.Config{ - "user": "sqlboiler_driver_user", - "pass": "sqlboiler", - "dbname": "sqlboiler_driver_test", - "host": "localhost", + "user": *flagUsername, + "pass": *flagPassword, + "dbname": *flagDatabase, + "host": *flagHostname, "port": 3306, "sslmode": "false", - "schema": "sqlboiler_driver_test", + "schema": *flagDatabase, } p := &MySQLDriver{} @@ -63,7 +68,7 @@ func TestDriver(t *testing.T) { t.Fatal(err) } - if *flagGolden { + if *flagOverwriteGolden { if err = ioutil.WriteFile("mysql.golden.json", got, 0664); err != nil { t.Fatal(err) } diff --git a/drivers/sqlboiler-mysql/sqlboiler-mysql b/drivers/sqlboiler-mysql/sqlboiler-mysql deleted file mode 100755 index 240177048..000000000 Binary files a/drivers/sqlboiler-mysql/sqlboiler-mysql and /dev/null differ diff --git a/drivers/sqlboiler-psql/driver/psql_test.go b/drivers/sqlboiler-psql/driver/psql_test.go index 07c6101a7..18c9bc178 100644 --- a/drivers/sqlboiler-psql/driver/psql_test.go +++ b/drivers/sqlboiler-psql/driver/psql_test.go @@ -12,6 +12,7 @@ import ( "bytes" "encoding/json" "flag" + "fmt" "io/ioutil" "os" "os/exec" @@ -21,7 +22,11 @@ import ( ) var ( - flagGolden = flag.Bool("test.golden", false, "Overwrite the golden file with the current execution results") + flagOverwriteGolden = flag.Bool("overwrite-golden", false, "Overwrite the golden file with the current execution results") + flagHostname = flag.String("hostname", "", "Connect to the server on the given host") + flagUsername = flag.String("username", "", "Username to use when connecting to server") + flagPassword = flag.String("password", "", "Password to use when connecting to server") + flagDatabase = flag.String("database", "", "The database to use") ) func TestDriver(t *testing.T) { @@ -31,8 +36,8 @@ func TestDriver(t *testing.T) { } out := &bytes.Buffer{} - createDB := exec.Command("psql", "--user", "sqlboiler_driver_user", "sqlboiler_driver_test") - createDB.Env = append([]string{"PGPASSWORD=sqlboiler"}, os.Environ()...) + createDB := exec.Command("psql", "-h", *flagHostname, "-U", *flagUsername, *flagDatabase) + createDB.Env = append([]string{fmt.Sprintf("PGPASSWORD=\"%s\"", *flagPassword)}, os.Environ()...) createDB.Stdout = out createDB.Stderr = out createDB.Stdin = bytes.NewReader(b) @@ -44,12 +49,12 @@ func TestDriver(t *testing.T) { t.Logf("psql output:\n%s\n", out.Bytes()) config := drivers.Config{ - "user": "sqlboiler_driver_user", - "pass": "sqlboiler", - "dbname": "sqlboiler_driver_test", - "host": "localhost", + "user": *flagUsername, + "pass": *flagPassword, + "dbname": *flagDatabase, + "host": *flagHostname, "port": 5432, - "sslmode": "require", + "sslmode": "disable", "schema": "public", } @@ -64,7 +69,7 @@ func TestDriver(t *testing.T) { t.Fatal(err) } - if *flagGolden { + if *flagOverwriteGolden { if err = ioutil.WriteFile("psql.golden.json", got, 0664); err != nil { t.Fatal(err) } diff --git a/drivers/sqlboiler-psql/sqlboiler-psql b/drivers/sqlboiler-psql/sqlboiler-psql deleted file mode 100755 index b648fe0ff..000000000 Binary files a/drivers/sqlboiler-psql/sqlboiler-psql and /dev/null differ diff --git a/randomize/randomize.go b/randomize/randomize.go index 81b0b3b33..96bc6292e 100644 --- a/randomize/randomize.go +++ b/randomize/randomize.go @@ -195,7 +195,11 @@ func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bo return nil } if fieldType == "uuid" { - value = null.NewString(uuid.NewV4().String(), true) + randomUUID, err := uuid.NewV4() + if err != nil { + return err + } + value = null.NewString(randomUUID.String(), true) field.Set(reflect.ValueOf(value)) return nil } @@ -268,8 +272,11 @@ func randomizeField(s *Seed, field reflect.Value, fieldType string, canBeNull bo return nil } if fieldType == "uuid" { - value = uuid.NewV4().String() - field.Set(reflect.ValueOf(value)) + value, err := uuid.NewV4() + if err != nil { + return err + } + field.Set(reflect.ValueOf(value.String())) return nil } if fieldType == "box" || fieldType == "line" || fieldType == "lseg" || @@ -390,7 +397,11 @@ func getArrayRandValue(s *Seed, typ reflect.Type, fieldType string) interface{} return types.StringArray{value, value} } if fieldType == "uuid" { - value := uuid.NewV4().String() + randomUUID, err := uuid.NewV4() + if err != nil { + return err + } + value := randomUUID.String() return types.StringArray{value, value} } if fieldType == "box" || fieldType == "line" || fieldType == "lseg" || diff --git a/strmangle/strmangle_test.go b/strmangle/strmangle_test.go index f7c54e724..a1b06013c 100644 --- a/strmangle/strmangle_test.go +++ b/strmangle/strmangle_test.go @@ -598,9 +598,9 @@ func TestReplaceReservedWords(t *testing.T) { for i, test := range tests { got := ReplaceReservedWords(test.Word) if test.Replace && !strings.HasSuffix(got, "_") { - t.Errorf("%i) want suffixed (%s), got: %s", i, test.Word, got) + t.Errorf("%d) want suffixed (%s), got: %s", i, test.Word, got) } else if !test.Replace && strings.HasSuffix(got, "_") { - t.Errorf("%i) want normal (%s), got: %s", i, test.Word, got) + t.Errorf("%d) want normal (%s), got: %s", i, test.Word, got) } } } diff --git a/testdata/Dockerfile b/testdata/Dockerfile index 034cedce7..6d0dc9f84 100644 --- a/testdata/Dockerfile +++ b/testdata/Dockerfile @@ -1,20 +1,20 @@ # This Dockerfile builds the image used for CI/testing. FROM ubuntu:16.04 +# Set PATH ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/opt/mssql-tools/bin -ENV GODIST go1.8.linux-amd64.tar.gz - -# Set up locales for sqlcmd (otherwise it breaks) -RUN locale-gen en_US.UTF-8 \ - && echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale \ - && echo "LANG=en_US.UTF-8" >> /etc/default/locale # Install bootstrap-y tools RUN apt-get update \ && apt-get install -y apt-transport-https software-properties-common python3-software-properties \ && apt-add-repository ppa:git-core/ppa \ && apt-get update \ - && apt-get install -y curl git + && apt-get install -y curl git make locales + +# Set up locales for sqlcmd (otherwise it breaks) +RUN locale-gen en_US.UTF-8 \ + && echo "LC_ALL=en_US.UTF-8" >> /etc/default/locale \ + && echo "LANG=en_US.UTF-8" >> /etc/default/locale # Install database clients # MySQL 8.0 is still in development, so we're using 5.7 which is already @@ -26,10 +26,10 @@ RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ && apt-get update \ && env ACCEPT_EULA=Y apt-get install -y git postgresql-client-9.6 mysql-client-5.7 mssql-tools unixodbc-dev -# Install Go -RUN curl -o $GODIST https://storage.googleapis.com/golang/$GODIST \ +# Install Go + Go based tooling +ENV GOLANG_VERSION 1.10 +RUN curl -o go.tar.gz "https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz" \ && rm -rf /usr/local/go \ - && tar -C /usr/local -xzf $GODIST - -RUN go get -u -v github.com/jstemmer/go-junit-report \ + && tar -C /usr/local -xzf go.tar.gz \ + && go get -u -v github.com/jstemmer/go-junit-report \ && mv /root/go/bin/go-junit-report /usr/bin/go-junit-report