From 3d1f3fc60936a7d50b0c6e559b645331466f1d28 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 2 Apr 2017 09:40:08 -0700 Subject: [PATCH 01/10] Use different schema names for different drivers --- main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index a2f9396..acc7b1e 100644 --- a/main.go +++ b/main.go @@ -73,7 +73,7 @@ func main() { // Set up the cobra root command flags rootCmd.PersistentFlags().StringP("output", "o", "models", "The name of the folder to output to") - rootCmd.PersistentFlags().StringP("schema", "s", "public", "The name of your database schema, for databases that support real schemas") + rootCmd.PersistentFlags().StringP("schema", "s", "", "schema name for drivers that support it (default psql: public, mssql: dbo)") rootCmd.PersistentFlags().StringP("pkgname", "p", "models", "The name you wish to assign to your generated package") rootCmd.PersistentFlags().StringP("basedir", "", "", "The base directory has the templates and templates_test folders") rootCmd.PersistentFlags().StringSliceP("blacklist", "b", nil, "Do not include these tables in your generated package") @@ -202,6 +202,10 @@ func preRun(cmd *cobra.Command, args []string) error { viper.Set("postgres.port", cmdConfig.Postgres.Port) } + if len(cmdConfig.Schema) == 0 { + cmdConfig.Schema = "public" + } + err = vala.BeginValidation().Validate( vala.StringNotEmpty(cmdConfig.Postgres.User, "postgres.user"), vala.StringNotEmpty(cmdConfig.Postgres.Host, "postgres.host"), @@ -280,6 +284,10 @@ func preRun(cmd *cobra.Command, args []string) error { viper.Set("mssql.port", cmdConfig.MSSQL.Port) } + if len(cmdConfig.Schema) == 0 { + cmdConfig.Schema = "dbo" + } + err = vala.BeginValidation().Validate( vala.StringNotEmpty(cmdConfig.MSSQL.User, "mssql.user"), vala.StringNotEmpty(cmdConfig.MSSQL.Host, "mssql.host"), From e4d1e606fdfd88dd07f1f9dffbf7a9defc230e5c Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 2 Apr 2017 10:00:42 -0700 Subject: [PATCH 02/10] CI for mssql - Fix a bug where mysql was never tested in CI (hah!) --- circle.yml | 222 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 196 insertions(+), 26 deletions(-) diff --git a/circle.yml b/circle.yml index ed75a12..68bc895 100644 --- a/circle.yml +++ b/circle.yml @@ -1,28 +1,198 @@ -test: - pre: - - mkdir -p /home/ubuntu/.go_workspace/src/github.com/jstemmer - - go get -u github.com/jstemmer/go-junit-report - - echo -e "[postgres]\nhost=\"localhost\"\nport=5432\nuser=\"ubuntu\"\ndbname=\"sqlboiler\"\n[mysql]\nhost=\"localhost\"\nport=3306\nuser=\"ubuntu\"\ndbname=\"sqlboiler\"\nsslmode=\"false\"" > sqlboiler.toml - - createdb -U ubuntu sqlboiler - - psql -U ubuntu sqlboiler < ./testdata/postgres_test_schema.sql - - echo "create database sqlboiler;" | mysql -u ubuntu - - mysql -u ubuntu sqlboiler < ./testdata/mysql_test_schema.sql - - ./sqlboiler postgres -o "postgres" - - ./sqlboiler postgres -o "mysql" - override: - - go test -v -race ./... > $CIRCLE_ARTIFACTS/gotest.txt - post: - - cat $CIRCLE_ARTIFACTS/gotest.txt | go-junit-report > $CIRCLE_TEST_REPORTS/junit.xml +version: 2 +jobs: + build: + working_directory: /root + docker: + - image: aarondl0/sqlboiler-test:latest -machine: - environment: - GODIST: "go1.7.linux-amd64.tar.gz" - post: - - mkdir -p download - - test -e download/$GODIST || curl -o download/$GODIST https://storage.googleapis.com/golang/$GODIST - - sudo rm -rf /usr/local/go - - sudo tar -C /usr/local -xzf download/$GODIST + - image: postgres:9.6 + environment: + POSTGRES_PASSWORD: psqlpassword -dependencies: - cache_directories: - - ~/download + - image: mysql:5.7 + environment: + MYSQL_ROOT_PASSWORD: mysqlpassword + + - image: microsoft/mssql-server-linux:ctp1-4 + environment: + ACCEPT_EULA: 'Y' + SA_PASSWORD: 'R@@tr@@t1234' + + environment: + GOPATH: /go + ROOTPATH: /go/src/github.com/vattle/sqlboiler + + steps: + - run: + name: Add PSQL Creds + command: | + echo "*:*:*:*:psqlpassword" > /root/.pgpass + chmod 600 /root/.pgpass + - run: + name: Add MySQL Creds + 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 + command: > + 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 + + - run: + name: Wait for MySQL + command: > + 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 + + - run: + name: Make GOPATH + command: mkdir -p /go/src/github.com/vattle/sqlboiler + + - checkout: + path: /go/src/github.com/vattle/sqlboiler + + - 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 + 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 + + - run: + name: Build SQLBoiler + command: | + cd $ROOTPATH; go get -v + cd $ROOTPATH; go build -v github.com/vattle/sqlboiler + + - run: + name: Configure SQLBoiler: PSQL + command: echo -e '[postgres]\nhost="localhost"\nport=5432\nuser="postgres"\ndbname="sqlboiler"\n' > $ROOTPATH/sqlboiler.toml + - run: + name: Configure SQLBoiler: MySQL + command: echo -e '[mysql]\nhost="localhost"\nport=3306\nuser="root"\ndbname="sqlboiler"\nsslmode="false"\n' >> $ROOTPATH/sqlboiler.toml + - run: + name: Configure SQLBoiler: MSSQL + command: echo -e '[mssql]\nhost="localhost"\nport=1433\nuser="sa"\npassword="R@@tr@@t1234"\ndbname="sqlboiler"\nsslmode="disable"\n' >> $ROOTPATH/sqlboiler.toml + + - 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 + + - run: + name: Test + command: | + cd $ROOTPATH + cp ./testdata/mssql_test_schema.sql mssql/tables_schema.sql + mkdir -p test_results/go + go test -v -race ./... > test_out.txt + cat test_out | go-junit-report > $ROOTPATH/test_results/go/out.xml + + - store_test_results: + path: $ROOTPATH/test_results +#test: +# pre: +# - echo -e "[postgres]\nhost=\"localhost\"\nport=5432\nuser=\"ubuntu\"\ndbname=\"sqlboiler\"\n" > sqlboiler.toml +# - createdb -U ubuntu sqlboiler +# - psql -U ubuntu sqlboiler < ./testdata/postgres_test_schema.sql +# +# - echo -e "[mysql]\nhost=\"localhost\"\nport=3306\nuser=\"ubuntu\"\ndbname=\"sqlboiler\"\nsslmode=\"false\"\n" >> sqlboiler.toml +# - echo "create database sqlboiler;" | mysql -u ubuntu +# - mysql -u ubuntu sqlboiler < ./testdata/mysql_test_schema.sql +# +# - echo -e "[mssql]\nhost=\"localhost\"\nport=1433\nuser=\"sa\"\ndbname=\"sqlboiler\"\nsslmode=\"disable\"\n" >> sqlboiler.toml +# - docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=R@@tr@@t1234' -p 1433:1433 -d --name mssql microsoft/mssql-server-linux +# - 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 ./testdata/mssql_test_schema.sql +# +# - ./sqlboiler -o postgres postgres +# - ./sqlboiler -o mysql mysql +# - ./sqlboiler -o mssql mssql +# - cp ./testdata/mssql_test_schema.sql mssql/tables_schema.sql +# override: +# - go test -v -race ./... > $CIRCLE_ARTIFACTS/gotest.txt +# post: +# - cat $CIRCLE_ARTIFACTS/gotest.txt | go-junit-report > $CIRCLE_TEST_REPORTS/junit.xml +# +#machine: +# environment: +# GODIST: go1.7.linux-amd64.tar.gz +# PATH: /home/ubuntu/.go_workspace/bin:/usr/local/go/bin:/home/ubuntu/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/opt/mssql-tools/bin +# post: +# - mkdir -p download +# - test -e download/$GODIST || curl -o download/$GODIST https://storage.googleapis.com/golang/$GODIST +# - sudo rm -rf /usr/local/go +# - sudo tar -C /usr/local -xzf download/$GODIST +# +#dependencies: +# pre: +# - mkdir -p /home/ubuntu/.go_workspace/src/github.com/jstemmer +# - go get -u github.com/jstemmer/go-junit-report +# +# - curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - +# - curl https://packages.microsoft.com/config/ubuntu/14.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list +# - sudo apt-get update; sudo apt-get install mssql-tools unixodbc-dev +# - docker pull microsoft/mssql-server-linux +# cache_directories: +# - ~/download From 3a38ed1f7af36d026cd8532e10104c9568e584f0 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 23 Apr 2017 16:14:37 -0700 Subject: [PATCH 03/10] Add Dockerfile --- testdata/Dockerfile | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 testdata/Dockerfile diff --git a/testdata/Dockerfile b/testdata/Dockerfile new file mode 100644 index 0000000..034cedc --- /dev/null +++ b/testdata/Dockerfile @@ -0,0 +1,35 @@ +# This Dockerfile builds the image used for CI/testing. +FROM ubuntu:16.04 + +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 + +# Install database clients +# MySQL 8.0 is still in development, so we're using 5.7 which is already +# available in Ubuntu 16.04 +RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ + && echo 'deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main' > /etc/apt/sources.list.d/psql.list \ + && curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \ + && curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/msprod.list \ + && 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 \ + && rm -rf /usr/local/go \ + && tar -C /usr/local -xzf $GODIST + +RUN go get -u -v github.com/jstemmer/go-junit-report \ + && mv /root/go/bin/go-junit-report /usr/bin/go-junit-report From 5ee4b06c9b60caaad9633a0909c81f92a2444d03 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 23 Apr 2017 16:16:07 -0700 Subject: [PATCH 04/10] Move CircleCI file to correct spot --- circle.yml => .circleci/config.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename circle.yml => .circleci/config.yml (100%) diff --git a/circle.yml b/.circleci/config.yml similarity index 100% rename from circle.yml rename to .circleci/config.yml From 85c9104d3494731dcd913889f5cb5c9551f8141a Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 23 Apr 2017 16:17:46 -0700 Subject: [PATCH 05/10] Fix syntax error --- .circleci/config.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 68bc895..e146724 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -121,27 +121,27 @@ jobs: cd $ROOTPATH; go build -v github.com/vattle/sqlboiler - run: - name: Configure SQLBoiler: PSQL + name: 'Configure SQLBoiler: PSQL' command: echo -e '[postgres]\nhost="localhost"\nport=5432\nuser="postgres"\ndbname="sqlboiler"\n' > $ROOTPATH/sqlboiler.toml - run: - name: Configure SQLBoiler: MySQL + name: 'Configure SQLBoiler: MySQL' command: echo -e '[mysql]\nhost="localhost"\nport=3306\nuser="root"\ndbname="sqlboiler"\nsslmode="false"\n' >> $ROOTPATH/sqlboiler.toml - run: - name: Configure SQLBoiler: MSSQL + name: 'Configure SQLBoiler: MSSQL' command: echo -e '[mssql]\nhost="localhost"\nport=1433\nuser="sa"\npassword="R@@tr@@t1234"\ndbname="sqlboiler"\nsslmode="disable"\n' >> $ROOTPATH/sqlboiler.toml - run: - name: Generate: PSQL + name: 'Generate: PSQL' command: cd $ROOTPATH; ./sqlboiler -o postgres postgres - run: - name: Generate: MySQL + name: 'Generate: MySQL' command: cd $ROOTPATH; ./sqlboiler -o mysql mysql - run: - name: Generate: MSSQL + name: 'Generate: MSSQL' command: cd $ROOTPATH; ./sqlboiler -o mssql mssql - run: - name: Test + name: Run Tests command: | cd $ROOTPATH cp ./testdata/mssql_test_schema.sql mssql/tables_schema.sql From 36ae141304a916b7b2bdea2bd36f592c2c68f782 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 23 Apr 2017 16:22:10 -0700 Subject: [PATCH 06/10] Turn off PSQL SSL in tests --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e146724..dcd26c2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,7 @@ jobs: - run: name: 'Configure SQLBoiler: PSQL' - command: echo -e '[postgres]\nhost="localhost"\nport=5432\nuser="postgres"\ndbname="sqlboiler"\n' > $ROOTPATH/sqlboiler.toml + command: echo -e '[postgres]\nhost="localhost"\nport=5432\nuser="postgres"\ndbname="sqlboiler"\nsslmode="disable"\n' > $ROOTPATH/sqlboiler.toml - run: name: 'Configure SQLBoiler: MySQL' command: echo -e '[mysql]\nhost="localhost"\nport=3306\nuser="root"\ndbname="sqlboiler"\nsslmode="false"\n' >> $ROOTPATH/sqlboiler.toml From 0b44c26a264f4b38cdab07666d3fa3f897d70378 Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 23 Apr 2017 16:27:32 -0700 Subject: [PATCH 07/10] Add passwords to psql/mysql --- .circleci/config.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index dcd26c2..94dc610 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,13 +122,13 @@ jobs: - run: name: 'Configure SQLBoiler: PSQL' - command: echo -e '[postgres]\nhost="localhost"\nport=5432\nuser="postgres"\ndbname="sqlboiler"\nsslmode="disable"\n' > $ROOTPATH/sqlboiler.toml + 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"\ndbname="sqlboiler"\nsslmode="false"\n' >> $ROOTPATH/sqlboiler.toml + 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"\npassword="R@@tr@@t1234"\ndbname="sqlboiler"\nsslmode="disable"\n' >> $ROOTPATH/sqlboiler.toml + command: echo -e '[mssql]\nhost="localhost"\nport=1433\nuser="sa"\npass="R@@tr@@t1234"\ndbname="sqlboiler"\nsslmode="disable"\n' >> $ROOTPATH/sqlboiler.toml - run: name: 'Generate: PSQL' From 7de817b111412e574cd1ac8b1bf13a49cc4a56da Mon Sep 17 00:00:00 2001 From: Aaron L Date: Sun, 23 Apr 2017 16:43:41 -0700 Subject: [PATCH 08/10] Add dep fetch to tests part --- .circleci/config.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 94dc610..d233e6a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -117,7 +117,7 @@ jobs: - run: name: Build SQLBoiler command: | - cd $ROOTPATH; go get -v + cd $ROOTPATH; go get -v -t cd $ROOTPATH; go build -v github.com/vattle/sqlboiler - run: @@ -140,17 +140,27 @@ jobs: name: 'Generate: MSSQL' command: cd $ROOTPATH; ./sqlboiler -o mssql mssql + - run: + name: Download generated and test deps + command: | + cd $ROOTPATH + go get -v -t ./... + - run: name: Run Tests command: | cd $ROOTPATH cp ./testdata/mssql_test_schema.sql mssql/tables_schema.sql - mkdir -p test_results/go - go test -v -race ./... > test_out.txt - cat test_out | go-junit-report > $ROOTPATH/test_results/go/out.xml + go test -v -race ./... | tee test_out.txt + + - run: + name: Convert test output to JUNIT + command: | + mkdir -p $HOME/test_results/go + cat $ROOTPATH/test_out.txt | go-junit-report > $HOME/test_results/go/out.xml - store_test_results: - path: $ROOTPATH/test_results + path: test_results #test: # pre: # - echo -e "[postgres]\nhost=\"localhost\"\nport=5432\nuser=\"ubuntu\"\ndbname=\"sqlboiler\"\n" > sqlboiler.toml From a3442a5ab499510227f9b4cea5d5280c6227569a Mon Sep 17 00:00:00 2001 From: Sergey Kurt Date: Fri, 28 Apr 2017 23:58:17 +0300 Subject: [PATCH 09/10] Fixed INSERT-SELECT deadlocks in tests --- templates_test/main_test/mssql_main.tpl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates_test/main_test/mssql_main.tpl b/templates_test/main_test/mssql_main.tpl index c1c76f2..ba46be7 100644 --- a/templates_test/main_test/mssql_main.tpl +++ b/templates_test/main_test/mssql_main.tpl @@ -68,6 +68,9 @@ func (m *mssqlTester) sslMode(mode string) string { func (m *mssqlTester) createTestDB() error { sql := fmt.Sprintf(` CREATE DATABASE %s; + GO + ALTER DATABASE %[1]s + SET READ_COMMITTED_SNAPSHOT ON; GO`, m.testDBName) return m.runCmd(sql, "sqlcmd", "-S", m.host, "-U", m.user, "-P", m.pass) } From ecad5334fbcd1f8e3ebcc686efa91250380af0de Mon Sep 17 00:00:00 2001 From: Aaron L Date: Fri, 28 Apr 2017 20:01:27 -0700 Subject: [PATCH 10/10] Fix MySQL protocol selection - If MySQL host exists on the filesystem as a file, then expect that this is actually a unix socket. If not, add protocol=tcp to force the mysql client to use tcp otherwise it tries unix sockets for no reason. Thanks MySQL. --- templates_test/main_test/mysql_main.tpl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/templates_test/main_test/mysql_main.tpl b/templates_test/main_test/mysql_main.tpl index fc43d3d..b95b32c 100644 --- a/templates_test/main_test/mysql_main.tpl +++ b/templates_test/main_test/mysql_main.tpl @@ -90,12 +90,23 @@ func (m *mysqlTester) makeOptionFile() error { return errors.Wrap(err, "failed to create option file") } + isTCP := false + _, err = os.Stat(m.host) + if os.IsNotExist(err) { + isTCP = true + } else if err != nil { + return errors.Wrap(err, "could not stat m.host") + } + fmt.Fprintln(tmp, "[client]") fmt.Fprintf(tmp, "host=%s\n", m.host) fmt.Fprintf(tmp, "port=%d\n", m.port) fmt.Fprintf(tmp, "user=%s\n", m.user) fmt.Fprintf(tmp, "password=%s\n", m.pass) fmt.Fprintf(tmp, "ssl-mode=%s\n", m.sslMode(m.sslmode)) + if isTCP { + fmt.Fprintln(tmp, "protocol=tcp") + } fmt.Fprintln(tmp, "[mysqldump]") fmt.Fprintf(tmp, "host=%s\n", m.host) @@ -103,6 +114,9 @@ func (m *mysqlTester) makeOptionFile() error { fmt.Fprintf(tmp, "user=%s\n", m.user) fmt.Fprintf(tmp, "password=%s\n", m.pass) fmt.Fprintf(tmp, "ssl-mode=%s\n", m.sslMode(m.sslmode)) + if isTCP { + fmt.Fprintln(tmp, "protocol=tcp") + } m.optionFile = tmp.Name()