Skip to content

Commit 91ede32

Browse files
authored
Merge pull request #160 from go-reform/v1-3
Release 1.3.2
2 parents 161dee9 + f718df1 commit 91ede32

File tree

14 files changed

+116
-89
lines changed

14 files changed

+116
-89
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ First of all, run `make deps` to install all dependencies. After that, you have
1616

1717
If you have Go, Docker and Docker Compose installed, you can run all tests and linters simply by running `make`.
1818

19+
You can also set `REFORM_TARGET` and `REFORM_IMAGE_VERSION` environment variables to test a specific combination.
20+
See [`.travis.yml`](../.travis.yml) for possible values.
1921

2022
### Direct
2123

.github/test-dc.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99
"os"
1010
"os/exec"
11+
"strconv"
1112
"strings"
1213
)
1314

@@ -84,7 +85,7 @@ func gen() {
8485
}
8586

8687
const filename = ".travis.yml"
87-
const start = "# Generated with 'go run .github/test-dc.go'."
88+
const start = "# Generated with 'go run .github/test-dc.go gen'."
8889
b, err := ioutil.ReadFile(filename)
8990
if err != nil {
9091
log.Fatal(err)
@@ -108,12 +109,14 @@ func testOne() {
108109
v := os.Getenv("REFORM_IMAGE_VERSION")
109110
log.Printf("REFORM_TARGET=%s REFORM_IMAGE_VERSION=%s", t, v)
110111

111-
for _, c := range []string{
112-
fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform pull", t),
113-
fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform up -d --remove-orphans --force-recreate", t),
114-
fmt.Sprintf("make %s", t),
115-
fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform down --remove-orphans --volumes", t),
116-
} {
112+
var commands []string
113+
if offline, _ := strconv.ParseBool(os.Getenv("REFORM_OFFLINE")); !offline {
114+
commands = append(commands, fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform pull", t))
115+
}
116+
commands = append(commands, fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform up -d --remove-orphans --force-recreate", t))
117+
commands = append(commands, fmt.Sprintf("make %s", t))
118+
commands = append(commands, fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform down --remove-orphans --volumes", t))
119+
for _, c := range commands {
117120
log.Print(c)
118121
args := strings.Split(c, " ")
119122
cmd := exec.Command(args[0], args[1:]...)

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
.idea/
33
*.cover
44
coverage.txt
5+
internal/test/sql/*_combined.tmp.sql
6+
reform-database.sqlite3

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ sudo: required
33
language: go
44

55
go:
6-
- 1.7.x
76
- 1.8.x
87
- 1.9.x
8+
- 1.10.x
99
- master
1010

1111
go_import_path: gopkg.in/reform.v1
@@ -37,7 +37,7 @@ env:
3737
global:
3838
- GORACE="halt_on_error=1"
3939

40-
# Generated with 'go run .github/test-dc.go'.
40+
# Generated with 'go run .github/test-dc.go gen'.
4141
# 16 combinations:
4242
# postgres: 9.3, 9.4, 9.5, 9.6, 10
4343
# mysql, mysql-traditional: 5.5, 5.6, 5.7, 8.0

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v1.3.2 (2018-07-23, https://github.com/go-reform/reform/milestones/v1.3.2)
4+
5+
* Go 1.8+ is now required due to changes in github.com/lib/pq driver.
6+
* Fixes in tests for MySQL 8, Go 1.10+ and latest versions of drivers.
7+
38
## v1.3.1 (2017-12-07, https://github.com/go-reform/reform/milestones/v1.3.1)
49

510
* No user-visible changes.

Makefile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ deps:
1414

1515
go get -u github.com/AlekSi/pointer
1616
go get -u github.com/stretchr/testify/...
17-
go get -u github.com/enodata/faker
17+
go get -u syreclabs.com/go/faker
1818
go get -u gopkg.in/alecthomas/gometalinter.v1
1919
go get -u github.com/AlekSi/gocoverutil
2020

@@ -44,11 +44,19 @@ test-db:
4444
internal/test/sql/$(REFORM_DATABASE)_drop.sql
4545
reform-db -db-driver="$(REFORM_DRIVER)" -db-source="$(REFORM_ROOT_SOURCE)" exec \
4646
internal/test/sql/$(REFORM_DATABASE)_create.sql
47-
reform-db -db-driver="$(REFORM_DRIVER)" -db-source="$(REFORM_INIT_SOURCE)" exec \
47+
48+
# TODO remove that hack in reform 1.4
49+
# https://github.com/go-reform/reform/issues/151
50+
# https://github.com/go-reform/reform/issues/157
51+
cat \
4852
internal/test/sql/$(REFORM_DATABASE)_init.sql \
4953
internal/test/sql/data.sql \
5054
internal/test/sql/$(REFORM_DATABASE)_data.sql \
51-
internal/test/sql/$(REFORM_DATABASE)_set.sql
55+
internal/test/sql/$(REFORM_DATABASE)_set.sql \
56+
> internal/test/sql/$(REFORM_DATABASE)_combined.tmp.sql
57+
reform-db -db-driver="$(REFORM_DRIVER)" -db-source="$(REFORM_INIT_SOURCE)" exec \
58+
internal/test/sql/$(REFORM_DATABASE)_combined.tmp.sql
59+
5260
go test $(REFORM_TEST_FLAGS) -covermode=count -coverprofile=reform-db.cover gopkg.in/reform.v1/reform-db
5361
go test $(REFORM_TEST_FLAGS) -covermode=count -coverprofile=reform.cover
5462
gocoverutil -coverprofile=coverage.txt merge *.cover
@@ -88,11 +96,11 @@ mysql-traditional: test
8896
# run unit tests and integration tests for SQLite3
8997
sqlite3: export REFORM_DATABASE = sqlite3
9098
sqlite3: export REFORM_DRIVER = sqlite3
91-
sqlite3: export REFORM_ROOT_SOURCE = /tmp/reform-database.sqlite3
92-
sqlite3: export REFORM_INIT_SOURCE = /tmp/reform-database.sqlite3
93-
sqlite3: export REFORM_TEST_SOURCE = /tmp/reform-database.sqlite3
99+
sqlite3: export REFORM_ROOT_SOURCE = $(CURDIR)/reform-database.sqlite3
100+
sqlite3: export REFORM_INIT_SOURCE = $(CURDIR)/reform-database.sqlite3
101+
sqlite3: export REFORM_TEST_SOURCE = $(CURDIR)/reform-database.sqlite3
94102
sqlite3: test
95-
rm -f /tmp/reform-database.sqlite3
103+
rm -f $(CURDIR)/reform-database.sqlite3
96104
make test-db
97105

98106
# run unit tests and integration tests for SQL Server (mssql driver)
@@ -122,7 +130,7 @@ win-mssql: export REFORM_ROOT_SOURCE = server=$(REFORM_SQL_HOST)\$(REFORM_SQL_IN
122130
win-mssql: export REFORM_INIT_SOURCE = server=$(REFORM_SQL_HOST)\$(REFORM_SQL_INSTANCE);database=reform-database
123131
win-mssql: export REFORM_TEST_SOURCE = server=$(REFORM_SQL_HOST)\$(REFORM_SQL_INSTANCE);database=reform-database
124132
win-mssql: test
125-
mingw32-make test-db
133+
make test-db
126134

127135
# Windows: run unit tests and integration tests for SQL Server (sqlserver driver)
128136
win-sqlserver: REFORM_SQL_HOST ?= 127.0.0.1
@@ -133,6 +141,6 @@ win-sqlserver: export REFORM_ROOT_SOURCE = sqlserver://$(REFORM_SQL_HOST)/$(REFO
133141
win-sqlserver: export REFORM_INIT_SOURCE = sqlserver://$(REFORM_SQL_HOST)/$(REFORM_SQL_INSTANCE)?database=reform-database
134142
win-sqlserver: export REFORM_TEST_SOURCE = sqlserver://$(REFORM_SQL_HOST)/$(REFORM_SQL_INSTANCE)?database=reform-database
135143
win-sqlserver: test
136-
mingw32-make test-db
144+
make test-db
137145

138146
.PHONY: docs parse reform reform-db

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ Supported SQL dialects:
2323
| SQLite3 | [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) (`sqlite3`) |
2424
| Microsoft SQL Server | [github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb) (`mssql`, `sqlserver`) | Windows: SQL2008R2SP2, SQL2012SP1, SQL2014, SQL2016. Linux: [`microsoft/mssql-server-linux:latest` Docker image](https://hub.docker.com/r/microsoft/mssql-server-linux/).
2525

26-
Note that for MySQL [`clientFoundRows=true`](https://github.com/go-sql-driver/mysql#clientfoundrows) flag is required.
26+
Notes:
27+
* [`clientFoundRows=true` flag](https://github.com/go-sql-driver/mysql#clientfoundrows) is required for `mysql` driver.
28+
* `mssql` driver is [deprecated](https://github.com/denisenkom/go-mssqldb#deprecated) (but not `sqlserver` driver).
29+
2730

2831
## Quickstart
2932

30-
1. Make sure you are using Go 1.7+. Install or update `reform` package, `reform` and `reform-db` commands
33+
1. Make sure you are using Go 1.8+. Install or update `reform` package, `reform` and `reform-db` commands
3134
(see about versioning below):
3235

3336
```

appveyor.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ clone_folder: c:\gopath\src\gopkg.in\reform.v1
55
environment:
66
GOPATH: c:\gopath
77
matrix:
8+
- REFORM_TARGET: sqlite3
9+
810
- REFORM_SQL_INSTANCE: SQL2008R2SP2
911
REFORM_TARGET: win-mssql
1012
- REFORM_SQL_INSTANCE: SQL2008R2SP2
@@ -26,21 +28,22 @@ environment:
2628
REFORM_TARGET: win-sqlserver
2729

2830
install:
29-
- powershell -file .github\appveyor-prepare-mssql.ps1
30-
- set PATH=%PATH%;C:\msys64\mingw64\bin;%GOPATH%\bin
31+
- if defined REFORM_SQL_INSTANCE powershell -file .github\appveyor-prepare-mssql.ps1
32+
- set PATH=C:\msys64\usr\bin;C:\msys64\mingw64\bin;%GOPATH%\bin;%PATH%
33+
- pacman -Rsc --noconfirm gcc
3134

3235
- go version
3336
# - echo %PATH%
3437
# - go env
35-
# - where mingw32-make
38+
# - where make
3639
# - where gcc
3740

3841
build_script:
39-
- mingw32-make deps
42+
- make deps
4043

4144
test_script:
42-
- mingw32-make %REFORM_TARGET%
43-
- mingw32-make check
45+
- make %REFORM_TARGET%
46+
- make check
4447

4548
on_success:
4649
- ls -al

base_test.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,30 @@ func checkForeignKeys(t *testing.T, q *reform.Querier) {
4545
require.True(t, enabled)
4646
}
4747

48-
// setIdentityInsert allows or disallows insertions of rows with set primary keys for MS SQL.
49-
func setIdentityInsert(t *testing.T, q *reform.Querier, table string, allow bool) {
48+
// withIdentityInsert executes an action with MS SQL IDENTITY_INSERT enabled for a table
49+
func withIdentityInsert(t *testing.T, q *reform.Querier, table string, action func()) {
5050
if q.Dialect != mssql.Dialect && q.Dialect != sqlserver.Dialect {
51+
action()
5152
return
5253
}
5354

54-
allowString := "OFF"
55-
if allow {
56-
allowString = "ON"
57-
}
58-
sql := fmt.Sprintf("SET IDENTITY_INSERT %s %s", q.QuoteIdentifier(table), allowString)
59-
_, err := q.Exec(sql)
55+
query := fmt.Sprintf("SET IDENTITY_INSERT %s %%s", q.QuoteIdentifier(table))
56+
57+
_, err := q.Exec(fmt.Sprintf(query, "ON"))
58+
require.NoError(t, err)
59+
60+
action()
61+
62+
_, err = q.Exec(fmt.Sprintf(query, "OFF"))
6063
require.NoError(t, err)
6164
}
6265

66+
func insertPersonWithID(t *testing.T, q *reform.Querier, str reform.Struct) error {
67+
var err error
68+
withIdentityInsert(t, q, "people", func() { err = q.Insert(str) })
69+
return err
70+
}
71+
6372
type ReformSuite struct {
6473
suite.Suite
6574
tx *reform.TX
@@ -80,8 +89,6 @@ func (s *ReformSuite) SetupTest() {
8089
s.Require().NoError(err)
8190

8291
s.q = s.tx.WithTag("test")
83-
84-
setIdentityInsert(s.T(), s.q, "people", false)
8592
}
8693

8794
func (s *ReformSuite) TearDownTest() {
@@ -161,8 +168,6 @@ func (s *ReformSuite) TestPlaceholders() {
161168
}
162169

163170
func (s *ReformSuite) TestTimezones() {
164-
setIdentityInsert(s.T(), s.q, "people", true)
165-
166171
t1 := time.Now()
167172
t2 := t1.UTC()
168173
vlat, err := time.LoadLocation("Asia/Vladivostok")
@@ -176,8 +181,11 @@ func (s *ReformSuite) TestTimezones() {
176181
q := fmt.Sprintf(`INSERT INTO people (id, name, created_at) VALUES `+
177182
`(11, '11', %s), (12, '12', %s), (13, '13', %s), (14, '14', %s)`,
178183
s.q.Placeholder(1), s.q.Placeholder(2), s.q.Placeholder(3), s.q.Placeholder(4))
179-
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
180-
s.NoError(err)
184+
185+
withIdentityInsert(s.T(), s.q, "people", func() {
186+
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
187+
s.NoError(err)
188+
})
181189

182190
q = `SELECT created_at, created_at FROM people WHERE id IN (11, 12, 13, 14) ORDER BY id`
183191
rows, err := s.q.Query(q)
@@ -200,8 +208,11 @@ func (s *ReformSuite) TestTimezones() {
200208
q := fmt.Sprintf(`INSERT INTO projects (id, name, start) VALUES `+
201209
`('11', '11', %s), ('12', '12', %s), ('13', '13', %s), ('14', '14', %s)`,
202210
s.q.Placeholder(1), s.q.Placeholder(2), s.q.Placeholder(3), s.q.Placeholder(4))
203-
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
204-
s.NoError(err)
211+
212+
withIdentityInsert(s.T(), s.q, "people", func() {
213+
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
214+
s.NoError(err)
215+
})
205216

206217
q = `SELECT start, start FROM projects WHERE id IN ('11', '12', '13', '14') ORDER BY id`
207218
rows, err := s.q.Query(q)

0 commit comments

Comments
 (0)