Skip to content

Commit

Permalink
Merge pull request #160 from go-reform/v1-3
Browse files Browse the repository at this point in the history
Release 1.3.2
  • Loading branch information
AlekSi authored Jul 23, 2018
2 parents 161dee9 + f718df1 commit 91ede32
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 89 deletions.
2 changes: 2 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ First of all, run `make deps` to install all dependencies. After that, you have

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

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

### Direct

Expand Down
17 changes: 10 additions & 7 deletions .github/test-dc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"os"
"os/exec"
"strconv"
"strings"
)

Expand Down Expand Up @@ -84,7 +85,7 @@ func gen() {
}

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

for _, c := range []string{
fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform pull", t),
fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform up -d --remove-orphans --force-recreate", t),
fmt.Sprintf("make %s", t),
fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform down --remove-orphans --volumes", t),
} {
var commands []string
if offline, _ := strconv.ParseBool(os.Getenv("REFORM_OFFLINE")); !offline {
commands = append(commands, fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform pull", t))
}
commands = append(commands, fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform up -d --remove-orphans --force-recreate", t))
commands = append(commands, fmt.Sprintf("make %s", t))
commands = append(commands, fmt.Sprintf("docker-compose --file=.github/docker-compose-%s.yml --project-name=reform down --remove-orphans --volumes", t))
for _, c := range commands {
log.Print(c)
args := strings.Split(c, " ")
cmd := exec.Command(args[0], args[1:]...)
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.idea/
*.cover
coverage.txt
internal/test/sql/*_combined.tmp.sql
reform-database.sqlite3
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ sudo: required
language: go

go:
- 1.7.x
- 1.8.x
- 1.9.x
- 1.10.x
- master

go_import_path: gopkg.in/reform.v1
Expand Down Expand Up @@ -37,7 +37,7 @@ env:
global:
- GORACE="halt_on_error=1"

# Generated with 'go run .github/test-dc.go'.
# Generated with 'go run .github/test-dc.go gen'.
# 16 combinations:
# postgres: 9.3, 9.4, 9.5, 9.6, 10
# mysql, mysql-traditional: 5.5, 5.6, 5.7, 8.0
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v1.3.2 (2018-07-23, https://github.com/go-reform/reform/milestones/v1.3.2)

* Go 1.8+ is now required due to changes in github.com/lib/pq driver.
* Fixes in tests for MySQL 8, Go 1.10+ and latest versions of drivers.

## v1.3.1 (2017-12-07, https://github.com/go-reform/reform/milestones/v1.3.1)

* No user-visible changes.
Expand Down
26 changes: 17 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ deps:

go get -u github.com/AlekSi/pointer
go get -u github.com/stretchr/testify/...
go get -u github.com/enodata/faker
go get -u syreclabs.com/go/faker
go get -u gopkg.in/alecthomas/gometalinter.v1
go get -u github.com/AlekSi/gocoverutil

Expand Down Expand Up @@ -44,11 +44,19 @@ test-db:
internal/test/sql/$(REFORM_DATABASE)_drop.sql
reform-db -db-driver="$(REFORM_DRIVER)" -db-source="$(REFORM_ROOT_SOURCE)" exec \
internal/test/sql/$(REFORM_DATABASE)_create.sql
reform-db -db-driver="$(REFORM_DRIVER)" -db-source="$(REFORM_INIT_SOURCE)" exec \

# TODO remove that hack in reform 1.4
# https://github.com/go-reform/reform/issues/151
# https://github.com/go-reform/reform/issues/157
cat \
internal/test/sql/$(REFORM_DATABASE)_init.sql \
internal/test/sql/data.sql \
internal/test/sql/$(REFORM_DATABASE)_data.sql \
internal/test/sql/$(REFORM_DATABASE)_set.sql
internal/test/sql/$(REFORM_DATABASE)_set.sql \
> internal/test/sql/$(REFORM_DATABASE)_combined.tmp.sql
reform-db -db-driver="$(REFORM_DRIVER)" -db-source="$(REFORM_INIT_SOURCE)" exec \
internal/test/sql/$(REFORM_DATABASE)_combined.tmp.sql

go test $(REFORM_TEST_FLAGS) -covermode=count -coverprofile=reform-db.cover gopkg.in/reform.v1/reform-db
go test $(REFORM_TEST_FLAGS) -covermode=count -coverprofile=reform.cover
gocoverutil -coverprofile=coverage.txt merge *.cover
Expand Down Expand Up @@ -88,11 +96,11 @@ mysql-traditional: test
# run unit tests and integration tests for SQLite3
sqlite3: export REFORM_DATABASE = sqlite3
sqlite3: export REFORM_DRIVER = sqlite3
sqlite3: export REFORM_ROOT_SOURCE = /tmp/reform-database.sqlite3
sqlite3: export REFORM_INIT_SOURCE = /tmp/reform-database.sqlite3
sqlite3: export REFORM_TEST_SOURCE = /tmp/reform-database.sqlite3
sqlite3: export REFORM_ROOT_SOURCE = $(CURDIR)/reform-database.sqlite3
sqlite3: export REFORM_INIT_SOURCE = $(CURDIR)/reform-database.sqlite3
sqlite3: export REFORM_TEST_SOURCE = $(CURDIR)/reform-database.sqlite3
sqlite3: test
rm -f /tmp/reform-database.sqlite3
rm -f $(CURDIR)/reform-database.sqlite3
make test-db

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

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

.PHONY: docs parse reform reform-db
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ Supported SQL dialects:
| SQLite3 | [github.com/mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) (`sqlite3`) |
| 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/).

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


## Quickstart

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

```
Expand Down
15 changes: 9 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ clone_folder: c:\gopath\src\gopkg.in\reform.v1
environment:
GOPATH: c:\gopath
matrix:
- REFORM_TARGET: sqlite3

- REFORM_SQL_INSTANCE: SQL2008R2SP2
REFORM_TARGET: win-mssql
- REFORM_SQL_INSTANCE: SQL2008R2SP2
Expand All @@ -26,21 +28,22 @@ environment:
REFORM_TARGET: win-sqlserver

install:
- powershell -file .github\appveyor-prepare-mssql.ps1
- set PATH=%PATH%;C:\msys64\mingw64\bin;%GOPATH%\bin
- if defined REFORM_SQL_INSTANCE powershell -file .github\appveyor-prepare-mssql.ps1
- set PATH=C:\msys64\usr\bin;C:\msys64\mingw64\bin;%GOPATH%\bin;%PATH%
- pacman -Rsc --noconfirm gcc

- go version
# - echo %PATH%
# - go env
# - where mingw32-make
# - where make
# - where gcc

build_script:
- mingw32-make deps
- make deps

test_script:
- mingw32-make %REFORM_TARGET%
- mingw32-make check
- make %REFORM_TARGET%
- make check

on_success:
- ls -al
Expand Down
43 changes: 27 additions & 16 deletions base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,30 @@ func checkForeignKeys(t *testing.T, q *reform.Querier) {
require.True(t, enabled)
}

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

allowString := "OFF"
if allow {
allowString = "ON"
}
sql := fmt.Sprintf("SET IDENTITY_INSERT %s %s", q.QuoteIdentifier(table), allowString)
_, err := q.Exec(sql)
query := fmt.Sprintf("SET IDENTITY_INSERT %s %%s", q.QuoteIdentifier(table))

_, err := q.Exec(fmt.Sprintf(query, "ON"))
require.NoError(t, err)

action()

_, err = q.Exec(fmt.Sprintf(query, "OFF"))
require.NoError(t, err)
}

func insertPersonWithID(t *testing.T, q *reform.Querier, str reform.Struct) error {
var err error
withIdentityInsert(t, q, "people", func() { err = q.Insert(str) })
return err
}

type ReformSuite struct {
suite.Suite
tx *reform.TX
Expand All @@ -80,8 +89,6 @@ func (s *ReformSuite) SetupTest() {
s.Require().NoError(err)

s.q = s.tx.WithTag("test")

setIdentityInsert(s.T(), s.q, "people", false)
}

func (s *ReformSuite) TearDownTest() {
Expand Down Expand Up @@ -161,8 +168,6 @@ func (s *ReformSuite) TestPlaceholders() {
}

func (s *ReformSuite) TestTimezones() {
setIdentityInsert(s.T(), s.q, "people", true)

t1 := time.Now()
t2 := t1.UTC()
vlat, err := time.LoadLocation("Asia/Vladivostok")
Expand All @@ -176,8 +181,11 @@ func (s *ReformSuite) TestTimezones() {
q := fmt.Sprintf(`INSERT INTO people (id, name, created_at) VALUES `+
`(11, '11', %s), (12, '12', %s), (13, '13', %s), (14, '14', %s)`,
s.q.Placeholder(1), s.q.Placeholder(2), s.q.Placeholder(3), s.q.Placeholder(4))
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
s.NoError(err)

withIdentityInsert(s.T(), s.q, "people", func() {
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
s.NoError(err)
})

q = `SELECT created_at, created_at FROM people WHERE id IN (11, 12, 13, 14) ORDER BY id`
rows, err := s.q.Query(q)
Expand All @@ -200,8 +208,11 @@ func (s *ReformSuite) TestTimezones() {
q := fmt.Sprintf(`INSERT INTO projects (id, name, start) VALUES `+
`('11', '11', %s), ('12', '12', %s), ('13', '13', %s), ('14', '14', %s)`,
s.q.Placeholder(1), s.q.Placeholder(2), s.q.Placeholder(3), s.q.Placeholder(4))
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
s.NoError(err)

withIdentityInsert(s.T(), s.q, "people", func() {
_, err := s.q.Exec(q, t1, t2, tVLAT, tHST)
s.NoError(err)
})

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

0 comments on commit 91ede32

Please sign in to comment.