Skip to content

Commit

Permalink
Fix missing wrapper to convert gherkin table to [][]string (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Dec 2, 2021
1 parent 7f4e767 commit 0ac0b7b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: golangci/[email protected]
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.41.1
version: v1.43.0

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ linters:
- scopelint # deprecated
- ifshort # too many false positives
- golint # deprecated
- varnamelen
- tagliatelle
- errname
- ireturn

issues:
exclude-use-default: false
Expand Down
4 changes: 4 additions & 0 deletions Database.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Feature: Database Query
_testdata/rows.csv
"""

And these rows are stored in table "my_table" of database "my_db"
| id | foo | bar | created_at | deleted_at |
| 1 | foo-1 | abc | 2021-01-01T00:00:00Z | NULL |

Then only these rows are available in table "my_table" of database "my_db"
| id | foo | bar | created_at | deleted_at |
| $id1 | $foo1 | abc | 2021-01-01T00:00:00Z | NULL |
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#GOLANGCI_LINT_VERSION := "v1.41.1" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v1.43.0" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
Expand All @@ -23,7 +23,7 @@ ifeq ($(DEVGO_PATH),)
DEVGO_PATH := $(shell GO111MODULE=on $(GO) list ${modVendor} -f '{{.Dir}}' -m github.com/bool64/dev)
ifeq ($(DEVGO_PATH),)
$(info Module github.com/bool64/dev not found, downloading.)
DEVGO_PATH := $(shell export GO111MODULE=on && $(GO) mod tidy && $(GO) list -f '{{.Dir}}' -m github.com/bool64/dev)
DEVGO_PATH := $(shell export GO111MODULE=on && $(GO) get github.com/bool64/dev && $(GO) list -f '{{.Dir}}' -m github.com/bool64/dev)
endif
endif

Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ go 1.13

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/Masterminds/squirrel v1.5.0
github.com/bool64/dev v0.1.38
github.com/Masterminds/squirrel v1.5.2
github.com/bool64/dev v0.1.43
github.com/bool64/shared v0.1.3
github.com/bool64/sqluct v0.1.9
github.com/cucumber/godog v0.12.0
github.com/cucumber/godog v0.12.2
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-memdb v1.3.2 // indirect
github.com/jmoiron/sqlx v1.3.4
github.com/stretchr/testify v1.7.0
github.com/swaggest/form/v5 v5.0.1
Expand Down
20 changes: 12 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/Masterminds/squirrel v1.5.0 h1:JukIZisrUXadA9pl3rMkjhiamxiB0cXiu+HGp/Y8cY8=
github.com/Masterminds/squirrel v1.5.0/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
github.com/Masterminds/squirrel v1.5.2 h1:UiOEi2ZX4RCSkpiNDQN5kro/XIBpSRk9iTqdIRPzUXE=
github.com/Masterminds/squirrel v1.5.2/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
Expand All @@ -32,8 +33,8 @@ github.com/bool64/ctxd v1.0.0/go.mod h1:+rjDVFNOJeO+xlvMqQfG0p53CzuRB7FhPSo5nWSk
github.com/bool64/dev v0.1.25/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
github.com/bool64/dev v0.1.28/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
github.com/bool64/dev v0.1.35/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
github.com/bool64/dev v0.1.38 h1:RJZlSdbIDW/2RAQykcMziptk4zx/UcZD3n36HU4Zivo=
github.com/bool64/dev v0.1.38/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
github.com/bool64/dev v0.1.43 h1:McAhPS6dBrNSN53K9+4dj4ntCjEf9pw/r8AwaXRKgX8=
github.com/bool64/dev v0.1.43/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
github.com/bool64/shared v0.1.3 h1:gj7XZPYa1flQsCg3q9AIju+W2A1jaexK0fdFu2XtaG0=
github.com/bool64/shared v0.1.3/go.mod h1:RF1p1Oi29ofgOvinBpetbF5mceOUP3kpMkvLbWOmtm0=
github.com/bool64/sqluct v0.1.9 h1:GzlJxGTYwdzCdXIpHTQN1GzSi8S1jC04FQI4ptpsdYU=
Expand All @@ -48,8 +49,8 @@ github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfc
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cucumber/gherkin-go/v19 v19.0.3 h1:mMSKu1077ffLbTJULUfM5HPokgeBcIGboyeNUof1MdE=
github.com/cucumber/gherkin-go/v19 v19.0.3/go.mod h1:jY/NP6jUtRSArQQJ5h1FXOUgk5fZK24qtE7vKi776Vw=
github.com/cucumber/godog v0.12.0 h1:xVOc9ML+1joT0CqcdQTpfXiT7G1hOLbCmlUnYOyJ80w=
github.com/cucumber/godog v0.12.0/go.mod h1:u6SD7IXC49dLpPN35kal0oYEjsXZWee4pW6Tm9t5pIc=
github.com/cucumber/godog v0.12.2 h1:7rxwPS907cCeJvgVCJGRjgz/zTyClBwwx5DJAa8zfeM=
github.com/cucumber/godog v0.12.2/go.mod h1:u6SD7IXC49dLpPN35kal0oYEjsXZWee4pW6Tm9t5pIc=
github.com/cucumber/messages-go/v16 v16.0.0/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g=
github.com/cucumber/messages-go/v16 v16.0.1 h1:fvkpwsLgnIm0qugftrw2YwNlio+ABe2Iu94Ap8GMYIY=
github.com/cucumber/messages-go/v16 v16.0.1/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g=
Expand All @@ -68,8 +69,9 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
Expand Down Expand Up @@ -101,10 +103,12 @@ github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyN
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-memdb v1.3.0 h1:xdXq34gBOMEloa9rlGStLxmfX/dyIK8htOv36dQUwHU=
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-memdb v1.3.0/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g=
github.com/hashicorp/go-memdb v1.3.2 h1:RBKHOsnSszpU6vxq80LzC2BaQjuuvoyaQbkLTf7V7g8=
github.com/hashicorp/go-memdb v1.3.2/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g=
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
Expand Down
6 changes: 4 additions & 2 deletions manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ func (m *Manager) registerPrerequisites(s *godog.ScenarioContext) {
})

s.Step(`these rows are stored in table "([^"]*)" of database "([^"]*)"[:]?$`,
m.theseRowsAreStoredInTableOfDatabase)
func(tableName, database string, data *godog.Table) error {
return m.theseRowsAreStoredInTableOfDatabase(tableName, database, Rows(data))
})

s.Step(`rows from this file are stored in table "([^"]*)" of database "([^"]*)"[:]?$`,
func(tableName, database string, filePath *godog.DocString) error {
Expand Down Expand Up @@ -321,7 +323,7 @@ func loadTableFromFile(filePath string) (rows [][]string, err error) {
return nil, err
}

defer func() {
defer func() { // nolint:gosec // False positive: G307: Deferring unsafe method "Close" on type "*os.File" (gosec)
clErr := f.Close()
if clErr != nil && err == nil {
err = clErr
Expand Down
16 changes: 12 additions & 4 deletions manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,24 @@ func TestManager_RegisterContext(t *testing.T) {
mock.ExpectExec(`DELETE FROM my_table`).
WillReturnResult(driver.ResultNoRows)

// And rows from this file are stored in table "my_table" of database "my_db"
// """
// _testdata/rows.csv
// """
mock.ExpectExec(`INSERT INTO my_table \(id,created_at,deleted_at,foo,bar\) VALUES .+`).
WithArgs(
1, mustParseTime("2021-01-01T00:00:00Z"), nil, "foo-1", "abc",
2, mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), "foo-1", "def",
3, mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), "foo-2", "hij",
).
WillReturnResult(driver.ResultNoRows)

// And these rows are stored in table "my_table" of database "my_db":
// | id | foo | bar | created_at | deleted_at |
// | 1 | foo-1 | abc | 2021-01-01T00:00:00Z | NULL |
// | 2 | foo-1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z |
// | 3 | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z |
mock.ExpectExec(`INSERT INTO my_table \(id,created_at,deleted_at,foo,bar\) VALUES .+`).
WithArgs(
1, mustParseTime("2021-01-01T00:00:00Z"), nil, "foo-1", "abc",
2, mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), "foo-1", "def",
3, mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), "foo-2", "hij",
).
WillReturnResult(driver.ResultNoRows)

Expand Down

0 comments on commit 0ac0b7b

Please sign in to comment.