diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml deleted file mode 100644 index 152d4a6..0000000 --- a/.github/workflows/bench.yml +++ /dev/null @@ -1,114 +0,0 @@ -# This script is provided by github.com/bool64/dev. -name: bench -on: - pull_request: - workflow_dispatch: - inputs: - old: - description: 'Old Ref' - required: false - default: 'master' - new: - description: 'New Ref' - required: true - -env: - GO111MODULE: "on" - CACHE_BENCHMARK: "off" # Enables benchmark result reuse between runs, may skew latency results. - RUN_BASE_BENCHMARK: "on" # Runs benchmark for PR base in case benchmark result is missing. - GO_VERSION: 1.17.x -jobs: - bench: - runs-on: ubuntu-latest - steps: - - name: Install Go stable - if: env.GO_VERSION != 'tip' - uses: actions/setup-go@v2 - with: - go-version: ${{ env.GO_VERSION }} - - name: Install Go tip - if: env.GO_VERSION == 'tip' - run: | - curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz - ls -lah gotip.tar.gz - mkdir -p ~/sdk/gotip - tar -C ~/sdk/gotip -xzf gotip.tar.gz - ~/sdk/gotip/bin/go version - echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }} - - name: Go cache - uses: actions/cache@v2 - with: - # In order: - # * Module download cache - # * Build cache (Linux) - path: | - ~/go/pkg/mod - ~/.cache/go-build - key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go-cache - - name: Restore benchstat - uses: actions/cache@v2 - with: - path: ~/go/bin/benchstat - key: ${{ runner.os }}-benchstat - - name: Restore base benchmark result - if: env.CACHE_BENCHMARK == 'on' - id: benchmark-base - uses: actions/cache@v2 - with: - path: | - bench-master.txt - bench-main.txt - # Use base sha for PR or new commit hash for master/main push in benchmark result key. - key: ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }} - - name: Checkout base code - if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '') - uses: actions/checkout@v2 - with: - ref: ${{ (github.event.pull_request.base.sha != '' ) && github.event.pull_request.base.sha || github.event.inputs.old }} - path: __base - - name: Run base benchmark - if: env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '') - run: | - export REF_NAME=master - cd __base - make | grep bench-run && (BENCH_COUNT=5 make bench-run bench-stat && cp bench-master.txt ../bench-master.txt) || echo "No benchmarks in base" - - name: Benchmark - id: bench - run: | - export REF_NAME=new - BENCH_COUNT=5 make bench - OUTPUT=$(make bench-stat-diff) - echo "${OUTPUT}" - OUTPUT="${OUTPUT//$'\n'/%0A}" - echo "::set-output name=diff::$OUTPUT" - OUTPUT=$(make bench-stat) - echo "${OUTPUT}" - OUTPUT="${OUTPUT//$'\n'/%0A}" - echo "::set-output name=result::$OUTPUT" - - name: Comment Benchmark Result - continue-on-error: true - uses: marocchino/sticky-pull-request-comment@v2 - with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - header: bench - message: | - ### Benchmark Result -
Benchmark diff with base branch - - ``` - ${{ steps.bench.outputs.diff }} - ``` -
- -
Benchmark result - - ``` - ${{ steps.bench.outputs.result }} - ``` -
diff --git a/.golangci.yml b/.golangci.yml index 97710e1..6f4af1f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,10 +16,14 @@ linters-settings: check-exported: false unparam: check-exported: true + cyclop: + max-complexity: 15 linters: enable-all: true disable: + - gosec + - nilnil - lll - maligned - gochecknoglobals diff --git a/LICENSE b/LICENSE index 3b9e882..8bc397f 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2021 bool64 +Copyright (c) 2022 Viacheslav Poturaev Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 4b37b06..32cb7be 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,6 @@ endif -include $(DEVGO_PATH)/makefiles/main.mk -include $(DEVGO_PATH)/makefiles/lint.mk -include $(DEVGO_PATH)/makefiles/test-unit.mk --include $(DEVGO_PATH)/makefiles/bench.mk -include $(DEVGO_PATH)/makefiles/reset-ci.mk # Add your custom targets here. diff --git a/README.md b/README.md index 7ece3e4..db22474 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,158 @@ -# go-template +# Cucumber database steps for Go -[![Build Status](https://github.com/bool64/go-template/workflows/test-unit/badge.svg)](https://github.com/bool64/go-template/actions?query=branch%3Amaster+workflow%3Atest-unit) -[![Coverage Status](https://codecov.io/gh/bool64/go-template/branch/master/graph/badge.svg)](https://codecov.io/gh/bool64/go-template) -[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/bool64/go-template) -[![Time Tracker](https://wakatime.com/badge/github/bool64/go-template.svg)](https://wakatime.com/badge/github/bool64/go-template) -![Code lines](https://sloc.xyz/github/bool64/go-template/?category=code) -![Comments](https://sloc.xyz/github/bool64/go-template/?category=comments) +[![Build Status](https://github.com/godogx/dbsteps/workflows/test/badge.svg)](https://github.com/godogx/dbsteps/actions?query=branch%3Amaster+workflow%3Atest) +[![Coverage Status](https://codecov.io/gh/bool64/dbsteps/branch/master/graph/badge.svg)](https://codecov.io/gh/bool64/dbsteps) +[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/godogx/dbsteps) +[![Time Tracker](https://wakatime.com/badge/github/bool64/dbsteps.svg)](https://wakatime.com/badge/github/bool64/dbsteps) +![Code lines](https://sloc.xyz/github/bool64/dbsteps/?category=code) +![Comments](https://sloc.xyz/github/bool64/dbsteps/?category=comments) - +This module implements database-related step definitions +for [`github.com/cucumber/godog`](https://github.com/cucumber/godog). -Project template with GitHub actions for Go. +## Database Configuration -## Usage +Databases instances should be configured with `Manager.Instances`. -Create a new repository from this template, check out it and run `./run_me.sh` to replace template name with name of -your repository. +```go +dbm := dbsteps.Manager{} + +dbm.Instances = map[string]dbsteps.Instance{ + "my_db": { + Storage: storage, + Tables: map[string]interface{}{ + "my_table": new(repository.MyRow), + "my_another_table": new(repository.MyAnotherRow), + }, + }, +} +``` + +Row types should be structs with `db` field tags, for example: + +```go +type MyRow struct { + ID int `db:"id"` + Name string `db:"name"` +} +``` + +These structures are used to map data between database and `gherkin` tables. + +## Table Mapper Configuration + +Table mapper allows customizing decoding string values from godog table cells into Go row structures and back. + +```go +tableMapper := dbsteps.NewTableMapper() + +// Apply JSON decoding to a particular type. +tableMapper.Decoder.RegisterFunc(func(s string) (interface{}, error) { + m := repository.Meta{} + err := json.Unmarshal([]byte(s), &m) + if err != nil { + return nil, err + } + return m, err +}, repository.Meta{}) + +// Apply string splitting to github.com/lib/pq.StringArray. +tableMapper.Decoder.RegisterFunc(func(s string) (interface{}, error) { + return pq.StringArray(strings.Split(s, ",")), nil +}, pq.StringArray{}) + +// Create database manager with custom mapper. +dbm := dbsteps.Manager{ + TableMapper: tableMapper, +} +``` + +## Step Definitions + +Delete all rows from table. + +```gherkin +Given there are no rows in table "my_table" of database "my_db" +``` + +Populate rows in a database. + +```gherkin +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 | +``` + +```gherkin +And rows from this file are stored in table "my_table" of database "my_db" + """ + path/to/rows.csv + """ +``` + +Assert rows existence in a database. + +For each row in gherkin table database is queried to find a row with `WHERE` condition that includes provided column +values. + +If a column has `NULL` value, it is excluded from `WHERE` condition. + +Column can contain variable (any unique string starting with `$` or other prefix configured with `Manager.VarPrefix`). +If variable has not yet been populated, it is excluded from `WHERE` condition and populated with value received from +database. When this variable is used in next steps, it replaces the value of column with value of variable. + +Variables can help to assert consistency of dynamic data, for example variable can be populated as ID of one entity and +then checked as foreign key value of another entity. This can be especially helpful in cases of UUIDs. + +If column value represents JSON array or object it is excluded from `WHERE` condition, value assertion is done by +comparing Go value mapped from database row field with Go value mapped from gherkin table cell. + +```gherkin +Then these rows are available in table "my_table" of database "my_db" +| id | foo | bar | created_at | deleted_at | +| $id1 | foo-1 | abc | 2021-01-01T00:00:00Z | NULL | +| $id2 | foo-1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | +| $id3 | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | +``` + +```gherkin +Then rows from this file are available in table "my_table" of database "my_db" + """ + path/to/rows.csv + """ +``` + +It is possible to check table contents exhaustively by adding "only" to step statement. Such assertion will also make +sure that total number of rows in database table matches number of rows in gherkin table. + +```gherkin +Then only these rows are available in table "my_table" of database "my_db" +| id | foo | bar | created_at | deleted_at | +| $id1 | foo-1 | abc | 2021-01-01T00:00:00Z | NULL | +| $id2 | foo-1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | +| $id3 | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | +``` + +```gherkin +Then only rows from this file are available in table "my_table" of database "my_db" + """ + path/to/rows.csv + """ +``` + +Assert no rows exist in a database. + +```gherkin +And no rows are available in table "my_another_table" of database "my_db" +``` + +The name of database instance `of database "my_db"` can be omitted in all steps, in such case `"default"` will be used from database instance name. + +## Concurrent Usage + +Please note, due to centralized nature of database instance, scenarios that work with same tables would conflict. +In order to avoid conflicts, `dbsteps` locks access to a specific scenario until that scenario is finished. +The lock is per table, so if scenarios are operating on different tables, they will not conflict. +It is safe to use concurrent scenarios. \ No newline at end of file diff --git a/_testdata/Database.feature b/_testdata/Database.feature new file mode 100644 index 0000000..f7af2e4 --- /dev/null +++ b/_testdata/Database.feature @@ -0,0 +1,27 @@ +Feature: Database Query + + Scenario: Successful Query + Given there are no rows in table "my_table" of database "my_db" + + And rows from this file are stored in table "my_table" of database "my_db" + """ + _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 | + | $id2 | $foo1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | + | $id3 | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | + + 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 | + | $id2 | $foo1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | + | $id3 | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | + + And no rows are available in table "my_another_table" of database "my_db" diff --git a/_testdata/DatabaseConcurrent.feature b/_testdata/DatabaseConcurrent.feature new file mode 100644 index 0000000..dfdc5c3 --- /dev/null +++ b/_testdata/DatabaseConcurrent.feature @@ -0,0 +1,19 @@ +Feature: No locking for different tables + + Scenario: Table 1 + Given I sleep + Given I should not be blocked for "db1::t1" + Given there are no rows in table "t1" of database "db1" + And I sleep + + Scenario: Table 2 + Given I sleep + Given I should not be blocked for "db2::t2" + Given there are no rows in table "t2" of database "db2" + And I sleep + + Scenario: Table 3 + Given I sleep + Given I should not be blocked for "db3::t3" + Given there are no rows in table "t3" of database "db3" + And I sleep diff --git a/_testdata/DatabaseConcurrentBlocked.feature b/_testdata/DatabaseConcurrentBlocked.feature new file mode 100644 index 0000000..029eb4d --- /dev/null +++ b/_testdata/DatabaseConcurrentBlocked.feature @@ -0,0 +1,19 @@ +Feature: No locking for different tables + + Scenario: Table 1 + Given I sleep + Given I should not be blocked for "db1::t1" + Given there are no rows in table "t1" of database "db1" + And I sleep + + Scenario: Table 1 again + Given I sleep + Given I should not be blocked for "db1::t1" + Given there are no rows in table "t1" of database "db1" + And I sleep + + Scenario: Table 3 + Given I sleep + Given I should not be blocked for "db3::t3" + Given there are no rows in table "t3" of database "db3" + And I sleep diff --git a/_testdata/DatabaseDefault.feature b/_testdata/DatabaseDefault.feature new file mode 100644 index 0000000..1dcec71 --- /dev/null +++ b/_testdata/DatabaseDefault.feature @@ -0,0 +1,27 @@ +Feature: Database Query + + Scenario: Successful Query + Given there are no rows in table "my_table" + + And rows from this file are stored in table "my_table" + """ + _testdata/rows.csv + """ + + And these rows are stored in table "my_table" + | 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" + | id | foo | bar | created_at | deleted_at | + | $id1 | $foo1 | abc | 2021-01-01T00:00:00Z | NULL | + | $id2 | $foo1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | + | $id3 | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | + + Then only these rows are available in table "my_table" + | id | foo | bar | created_at | deleted_at | + | $id1 | $foo1 | abc | 2021-01-01T00:00:00Z | NULL | + | $id2 | $foo1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | + | $id3 | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | + + And no rows are available in table "my_another_table" diff --git a/_testdata/DatabaseFail.feature b/_testdata/DatabaseFail.feature new file mode 100644 index 0000000..859cc49 --- /dev/null +++ b/_testdata/DatabaseFail.feature @@ -0,0 +1,6 @@ +Feature: Database Query + + Scenario: Failing Query + Then only these rows are available 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 | diff --git a/_testdata/rows.csv b/_testdata/rows.csv new file mode 100644 index 0000000..010bcca --- /dev/null +++ b/_testdata/rows.csv @@ -0,0 +1,4 @@ +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 diff --git a/dev_test.go b/dev_test.go index 99a9b88..265a9c4 100644 --- a/dev_test.go +++ b/dev_test.go @@ -1,3 +1,3 @@ -package mypackage_test +package dbsteps_test import _ "github.com/bool64/dev" // Include CI/Dev scripts to project. diff --git a/go.mod b/go.mod index 2067a03..54edaca 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,31 @@ -module github.com/bool64/go-template +module github.com/godogx/dbsteps go 1.17 -require github.com/bool64/dev v0.2.5 +require ( + github.com/DATA-DOG/go-sqlmock v1.5.0 + github.com/Masterminds/squirrel v1.5.2 + github.com/bool64/dev v0.2.5 + github.com/bool64/shared v0.1.4 + github.com/bool64/sqluct v0.1.9 + github.com/cucumber/godog v0.12.3 + github.com/jmoiron/sqlx v1.3.4 + github.com/stretchr/testify v1.7.0 + github.com/swaggest/form/v5 v5.0.1 +) + +require ( + github.com/bool64/ctxd v1.0.0 // indirect + github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect + github.com/cucumber/messages-go/v16 v16.0.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect + 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/hashicorp/golang-lru v0.5.4 // indirect + github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect + github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect +) diff --git a/go.sum b/go.sum index ed7b77d..6752e28 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,355 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= +cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= +cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= +cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= +cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= +cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= +cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= +cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk= +cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= +cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= +dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +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/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= +github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= +github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= +github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84= +github.com/bool64/ctxd v1.0.0 h1:Btvo6BU5FulG7H2V9m5Il/2vcqT0nxe86AiEpbG08/I= +github.com/bool64/ctxd v1.0.0/go.mod h1:+rjDVFNOJeO+xlvMqQfG0p53CzuRB7FhPSo5nWSkpQ0= +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.2.5 h1:H0bylghwcjDBBhEwSFTjArEO9Dr8cCaB54QSOF7esOA= github.com/bool64/dev v0.2.5/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU= +github.com/bool64/shared v0.1.4 h1:zwtb1dl2QzDa9TJOq2jzDTdb5IPf9XlxTGKN8cySWT0= +github.com/bool64/shared v0.1.4/go.mod h1:ryGjsnQFh6BnEXClfVlEJrzjwzat7CmA8PNS5E+jPp0= +github.com/bool64/sqluct v0.1.9 h1:GzlJxGTYwdzCdXIpHTQN1GzSi8S1jC04FQI4ptpsdYU= +github.com/bool64/sqluct v0.1.9/go.mod h1:rlpF6TzZ601Tb4mxdSJP1ZbnBdJgssXWJ6+TCrq/J8I= +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= +github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= +github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= +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.3 h1:nBshklqcWho/joTFtSBfyD4KYkvftwwf0r0XpX6ajNU= +github.com/cucumber/godog v0.12.3/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= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= +github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= +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/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= +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= +github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= +github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= +github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= +github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= +github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= +github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= +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/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= +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= +github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= +github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= +github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE= +github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= +github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= +github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc= +github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= +github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64= +github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= +github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= +github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= +github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/jmoiron/sqlx v1.3.4 h1:wv+0IJZfL5z0uZoUjlpKgHkgaFSYD+r9CfrXjEXsO7w= +github.com/jmoiron/sqlx v1.3.4/go.mod h1:2BljVx/86SuTyjE+aPYlHCTNvZrnJXghYGpNiXLBMCQ= +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= +github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw= +github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o= +github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk= +github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw= +github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= +github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= +github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= +github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg= +github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= +github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= +github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= +github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI= +github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg= +github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY= +github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= +github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= +github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= +github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI= +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/viper v1.7.0/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= +github.com/swaggest/form/v5 v5.0.1 h1:YQH0REX7iMKhtoVPWXREZgbt50VYXNCKK61psnD8Fgo= +github.com/swaggest/form/v5 v5.0.1/go.mod h1:vdnaSTze7cxVKhWiCabrfm1YeLwWLpb9P941Gxv4FnA= +github.com/swaggest/usecase v0.1.5 h1:xMDWXnYGysVaF2f3ZnmDsn2FlZ8fd3FJD+O+8wl4aNQ= +github.com/swaggest/usecase v0.1.5/go.mod h1:uubX4ZbjQK1Bnl0xX9hOYpb/IUiSoVKk/yQImawbNMU= +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= +go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= +go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= +golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= +golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= +golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= +golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= +golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= +golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= +google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= +google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= +google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= +google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= +google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= +google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ= +gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= +rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= diff --git a/manager.go b/manager.go new file mode 100644 index 0000000..b728523 --- /dev/null +++ b/manager.go @@ -0,0 +1,931 @@ +// Package dbsteps provides godog steps to handle database state. +// +// Database Configuration +// +// Databases instances should be configured with Manager.Instances. +// +// dbm := dbsteps.Manager{} +// +// dbm.Instances = map[string]dbsteps.Instance{ +// "my_db": { +// Storage: storage, +// Tables: map[string]interface{}{ +// "my_table": new(repository.MyRow), +// "my_another_table": new(repository.MyAnotherRow), +// }, +// }, +// } +// +// Table TableMapper Configuration +// +// Table mapper allows customizing decoding string values from godog table cells into Go row structures and back. +// +// tableMapper := dbsteps.NewTableMapper() +// +// // Apply JSON decoding to a particular type. +// tableMapper.Decoder.RegisterFunc(func(s string) (interface{}, error) { +// m := repository.Meta{} +// err := json.Unmarshal([]byte(s), &m) +// if err != nil { +// return nil, err +// } +// return m, err +// }, repository.Meta{}) +// +// // Apply string splitting to github.com/lib/pq.StringArray. +// tableMapper.Decoder.RegisterFunc(func(s string) (interface{}, error) { +// return pq.StringArray(strings.Split(s, ",")), nil +// }, pq.StringArray{}) +// +// // Create database manager with custom mapper. +// dbm := dbsteps.Manager{ +// TableMapper: tableMapper, +// } +// +// +// Step Definitions +// +// Delete all rows from table. +// +// Given there are no rows in table "my_table" of database "my_db" +// +// Populate rows in a database with a gherkin table. +// +// 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 | +// +// Or with an CSV file +// +// And rows from this file are stored in table "my_table" of database "my_db" +// """ +// path/to/rows.csv +// """ +// +// Assert rows existence in a database. +// +// For each row in gherkin table DB is queried to find a row with WHERE condition that includes +// provided column values. +// +// If a column has NULL value, it is excluded from WHERE condition. +// +// Column can contain variable (any unique string starting with $ or other prefix configured with Manager.VarPrefix). +// If variable has not yet been populated, it is excluded from WHERE condition and populated with value received +// from database. When this variable is used in next steps, it replaces the value of column with value of variable. +// +// Variables can help to assert consistency of dynamic data, for example variable can be populated as ID of one entity +// and then checked as foreign key value of another entity. This can be especially helpful in cases of UUIDs. +// +// If column value represents JSON array or object it is excluded from WHERE condition, value assertion is done +// by comparing Go value mapped from database row field with Go value mapped from gherkin table cell. +// +// Then these rows are available in table "my_table" of database "my_db" +// | id | foo | bar | created_at | deleted_at | +// | $id1 | foo-1 | abc | 2021-01-01T00:00:00Z | NULL | +// | $id2 | foo-1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | +// | $id3 | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | +// +// Rows can be also loaded from CSV file. +// +// Then rows from this file are available in table "my_table" of database "my_db" +// """ +// path/to/rows.csv +// """ +// +// It is possible to check table contents exhaustively by adding "only" to step statement. Such assertion will also +// make sure that total number of rows in database table matches number of rows in gherkin table. +// +// Then only these rows are available in table "my_table" of database "my_db" +// | id | foo | bar | created_at | deleted_at | +// | $id1 | foo-1 | abc | 2021-01-01T00:00:00Z | NULL | +// | $id2 | foo-1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | +// | $id3 | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | +// +// Rows can be also loaded from CSV file. +// +// Then only rows from this file are available in table "my_table" of database "my_db" +// """ +// path/to/rows.csv +// """ +// +// Assert no rows exist in a database. +// +// And no rows are available in table "my_another_table" of database "my_db" +package dbsteps + +import ( + "context" + "encoding/csv" + "encoding/json" + "errors" + "fmt" + "os" + "reflect" + "strings" + "time" + + "github.com/Masterminds/squirrel" + "github.com/bool64/shared" + "github.com/bool64/sqluct" + "github.com/cucumber/godog" + "github.com/jmoiron/sqlx" + "github.com/stretchr/testify/assert" + "github.com/swaggest/form/v5" +) + +// Default is the name of default database. +const Default = "default" + +// RegisterSteps adds database manager context to test suite. +func (m *Manager) RegisterSteps(s *godog.ScenarioContext) { + m.sync.register(s) + m.registerPrerequisites(s) + m.registerAssertions(s) +} + +func (m *Manager) registerPrerequisites(s *godog.ScenarioContext) { + s.Step(`no rows in table "([^"]*)" of database "([^"]*)"$`, + m.noRowsInTableOfDatabase) + + s.Step(`no rows in table "([^"]*)"$`, + func(ctx context.Context, tableName string) (context.Context, error) { + return m.noRowsInTableOfDatabase(ctx, tableName, Default) + }) + + s.Step(`these rows are stored in table "([^"]*)" of database "([^"]*)"[:]?$`, + func(ctx context.Context, tableName, database string, data *godog.Table) (context.Context, error) { + return m.theseRowsAreStoredInTableOfDatabase(ctx, tableName, database, Rows(data)) + }) + + s.Step(`rows from this file are stored in table "([^"]*)" of database "([^"]*)"[:]?$`, + func(ctx context.Context, tableName, database string, filePath string) (context.Context, error) { + return m.rowsFromThisFileAreStoredInTableOfDatabase(ctx, tableName, database, filePath) + }) + + s.Step(`these rows are stored in table "([^"]*)"[:]?$`, + func(ctx context.Context, tableName string, data *godog.Table) (context.Context, error) { + return m.theseRowsAreStoredInTableOfDatabase(ctx, tableName, Default, Rows(data)) + }) + + s.Step(`rows from this file are stored in table "([^"]*)"[:]?$`, + func(ctx context.Context, tableName string, filePath string) (context.Context, error) { + return m.rowsFromThisFileAreStoredInTableOfDatabase(ctx, tableName, Default, filePath) + }) +} + +func (m *Manager) registerAssertions(s *godog.ScenarioContext) { + s.Step(`only rows from this file are available in table "([^"]*)" of database "([^"]*)"[:]?$`, + func(ctx context.Context, tableName, database string, filePath string) (context.Context, error) { + return m.onlyRowsFromThisFileAreAvailableInTableOfDatabase(ctx, tableName, database, filePath) + }) + + s.Step(`only these rows are available in table "([^"]*)" of database "([^"]*)"[:]?$`, + func(ctx context.Context, tableName, database string, data *godog.Table) (context.Context, error) { + return m.onlyTheseRowsAreAvailableInTableOfDatabase(ctx, tableName, database, Rows(data)) + }) + + s.Step(`only rows from this file are available in table "([^"]*)"[:]?$`, + func(ctx context.Context, tableName string, filePath string) (context.Context, error) { + return m.onlyRowsFromThisFileAreAvailableInTableOfDatabase(ctx, tableName, Default, filePath) + }) + + s.Step(`only these rows are available in table "([^"]*)"[:]?$`, + func(ctx context.Context, tableName string, data *godog.Table) (context.Context, error) { + return m.onlyTheseRowsAreAvailableInTableOfDatabase(ctx, tableName, Default, Rows(data)) + }) + + s.Step(`no rows are available in table "([^"]*)" of database "([^"]*)"$`, + m.noRowsAreAvailableInTableOfDatabase) + + s.Step(`no rows are available in table "([^"]*)"$`, + func(ctx context.Context, tableName string) (context.Context, error) { + return m.noRowsAreAvailableInTableOfDatabase(ctx, tableName, Default) + }) + + s.Step(`rows from this file are available in table "([^"]*)" of database "([^"]*)"[:]?$`, + m.rowsFromThisFileAreAvailableInTableOfDatabase) + + s.Step(`these rows are available in table "([^"]*)" of database "([^"]*)"[:]?$`, + func(ctx context.Context, tableName, database string, data *godog.Table) (context.Context, error) { + return m.theseRowsAreAvailableInTableOfDatabase(ctx, tableName, database, Rows(data)) + }) + + s.Step(`rows from this file are available in table "([^"]*)"[:]?$`, + func(ctx context.Context, tableName string, filePath string) (context.Context, error) { + return m.rowsFromThisFileAreAvailableInTableOfDatabase(ctx, tableName, Default, filePath) + }) + + s.Step(`these rows are available in table "([^"]*)"[:]?$`, + func(ctx context.Context, tableName string, data *godog.Table) (context.Context, error) { + return m.theseRowsAreAvailableInTableOfDatabase(ctx, tableName, Default, Rows(data)) + }) +} + +// NewManager initializes instance of database Manager. +func NewManager() *Manager { + return &Manager{ + TableMapper: NewTableMapper(), + Instances: make(map[string]Instance), + sync: newSynchronized(nil), + Vars: &shared.Vars{}, + } +} + +// Manager owns database connections. +type Manager struct { + sync *synchronized + + TableMapper *TableMapper + Instances map[string]Instance + + // Vars allow sharing vars with other steps. + Vars *shared.Vars +} + +// Instance provides database instance. +type Instance struct { + Storage *sqluct.Storage + // Tables is a map of row structures per table name. + // Example: `"my_table": new(MyEntityRow)` + Tables map[string]interface{} + // PostNoRowsStatements is a map of SQL statement list per table name. + // They are executed after `no rows in table` step. + // Example: `"my_table": []string{"ALTER SEQUENCE my_table_id_seq RESTART"}`. + PostCleanup map[string][]string + + vars *shared.Vars +} + +// RegisterJSONTypes registers types of provided values to unmarshal as JSON when decoding from string. +// +// Arguments should match types of fields in row entities. +// If field is a pointer, argument should be a pointer: e.g. new(MyType). +// If field is not a pointer, argument should not be a pointer: e.g. MyType{}. +func (m *Manager) RegisterJSONTypes(values ...interface{}) { + for _, t := range values { + rt := reflect.TypeOf(t) + m.TableMapper.Decoder.RegisterFunc(func(s string) (interface{}, error) { + v := reflect.New(rt) + err := json.Unmarshal([]byte(s), v.Interface()) + + return reflect.Indirect(v).Interface(), err + }, t) + } +} + +func (m *Manager) instance(ctx context.Context, tableName, dbName string) (Instance, interface{}, context.Context, error) { + if dbName == "" { + dbName = Default + } + + instance, found := m.Instances[dbName] + if !found { + return Instance{}, nil, ctx, fmt.Errorf("%w %s", errUnknownDatabase, dbName) + } + + row, found := instance.Tables[tableName] + if !found { + return Instance{}, nil, ctx, fmt.Errorf("%w %s in database %s", errUnknownTable, tableName, dbName) + } + + // Locking per table. + _, err := m.sync.acquireLock(ctx, dbName+"::"+tableName) + if err != nil { + return Instance{}, nil, ctx, err + } + + if m.Vars != nil { + ctx, instance.vars = m.Vars.Fork(ctx) + } + + return instance, row, ctx, nil +} + +func (m *Manager) noRowsInTableOfDatabase(ctx context.Context, tableName, dbName string) (context.Context, error) { + instance, _, ctx, err := m.instance(ctx, tableName, dbName) + if err != nil { + return ctx, err + } + + // Deleting from table + _, err = instance.Storage.Exec( + ctx, + instance.Storage.DeleteStmt(tableName), + ) + if err != nil { + return ctx, fmt.Errorf("failed to delete from table %s in db %s: %w", tableName, dbName, err) + } + + if instance.PostCleanup != nil { + for _, statement := range instance.PostCleanup[tableName] { + _, err := instance.Storage.Exec( + ctx, + sqluct.StringStatement(statement), + ) + if err != nil { + return ctx, fmt.Errorf("failed to execute post cleanup statement %q for table %s in db %s: %w", + statement, tableName, dbName, err) + } + } + } + + return ctx, err +} + +var errMissingFileName = errors.New("missing file name") + +func loadTableFromFile(filePath string) (rows [][]string, err error) { + if filePath == "" { + return nil, errMissingFileName + } + + f, err := os.Open(filePath) // nolint:gosec // Intended file inclusion. + if err != nil { + return nil, err + } + + 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 + } + }() + + c := csv.NewReader(f) + + rows, err = c.ReadAll() + if err != nil { + return nil, fmt.Errorf("failed to read CSV: %w", err) + } + + return rows, nil +} + +// Rows converts godog table to a nested slice of strings. +func Rows(data *godog.Table) [][]string { + d := make([][]string, 0, len(data.Rows)) + + for _, r := range data.Rows { + row := make([]string, 0, len(r.Cells)) + + for _, c := range r.Cells { + row = append(row, c.Value) + } + + d = append(d, row) + } + + return d +} + +func (m *Manager) rowsFromThisFileAreStoredInTableOfDatabase(ctx context.Context, tableName, dbName string, filePath string) (context.Context, error) { + data, err := loadTableFromFile(filePath) + if err != nil { + return ctx, fmt.Errorf("failed to load rows from file: %w", err) + } + + return m.theseRowsAreStoredInTableOfDatabase(ctx, tableName, dbName, data) +} + +func (m *Manager) theseRowsAreStoredInTableOfDatabase(ctx context.Context, tableName, dbName string, data [][]string) (context.Context, error) { + instance, row, ctx, err := m.instance(ctx, tableName, dbName) + if err != nil { + return ctx, err + } + + // Reading rows. + rows, err := m.TableMapper.SliceFromTable(data, row) + if err != nil { + return ctx, fmt.Errorf("failed to map rows table: %w", err) + } + + colNames := data[0] + + storage := instance.Storage + stmt := storage.InsertStmt(tableName, rows, sqluct.Columns(colNames...)) + + // Inserting rows. + _, err = storage.Exec(ctx, stmt) + + if err != nil { + query, args, toSQLErr := stmt.ToSql() + if toSQLErr != nil { + return ctx, toSQLErr + } + + return ctx, fmt.Errorf("failed to insert rows %q, %v: %w", query, args, err) + } + + return ctx, err +} + +func (m *Manager) onlyRowsFromThisFileAreAvailableInTableOfDatabase(ctx context.Context, tableName, dbName string, filePath string) (context.Context, error) { + data, err := loadTableFromFile(filePath) + if err != nil { + return ctx, fmt.Errorf("failed to load rows from file: %w", err) + } + + return m.assertRows(ctx, tableName, dbName, data, true) +} + +func (m *Manager) onlyTheseRowsAreAvailableInTableOfDatabase(ctx context.Context, tableName, dbName string, data [][]string) (context.Context, error) { + return m.assertRows(ctx, tableName, dbName, data, true) +} + +func (m *Manager) noRowsAreAvailableInTableOfDatabase(ctx context.Context, tableName, dbName string) (context.Context, error) { + return m.assertRows(ctx, tableName, dbName, nil, true) +} + +func (m *Manager) rowsFromThisFileAreAvailableInTableOfDatabase(ctx context.Context, tableName, dbName string, filePath string) (context.Context, error) { + data, err := loadTableFromFile(filePath) + if err != nil { + return ctx, fmt.Errorf("failed to load rows from file: %w", err) + } + + return m.assertRows(ctx, tableName, dbName, data, false) +} + +func (m *Manager) theseRowsAreAvailableInTableOfDatabase(ctx context.Context, tableName, dbName string, data [][]string) (context.Context, error) { + return m.assertRows(ctx, tableName, dbName, data, false) +} + +type testingT struct { + Err error +} + +func (t *testingT) Errorf(format string, args ...interface{}) { + t.Err = fmt.Errorf(format, args...) // nolint:goerr113 +} + +type tableQuery struct { + storage *sqluct.Storage + mapper *TableMapper + table string + data [][]string + row interface{} + colNames []string + skipWhereCols []string + postCheck []string + vars *shared.Vars +} + +func (t *tableQuery) exposeContents(err error) error { + qb := t.storage.SelectStmt(t.table, t.row).Limit(50) + + var colNames []string + + if t.data != nil { + colNames = t.data[0] + } + + table, queryErr := t.queryExistingRows(t.storage, colNames, qb) + if queryErr != nil { + err = fmt.Errorf("%w, failed to query existing rows: %v", err, queryErr) + } else { + err = fmt.Errorf("%w, rows available:\n%v", err, table) + } + + return err +} + +func (t *tableQuery) checkCount(ctx context.Context) error { + dataCnt := 0 + + if t.data != nil { + dataCnt = len(t.data) - 1 + } + + qb := t.storage.QueryBuilder(). + Select("COUNT(1) AS c"). + From(t.table) + + cnt := struct { + Count int `db:"c"` + }{} + + err := t.storage.Select(ctx, qb, &cnt) + if err != nil { + return err + } + + if cnt.Count != dataCnt { + return fmt.Errorf("%w: %d expected, %d found", + errInvalidNumberOfRows, dataCnt, cnt.Count) + } + + return nil +} + +func (m *Manager) makeTableQuery(ctx context.Context, tableName, dbName string, data [][]string) (*tableQuery, context.Context, error) { + instance, row, ctx, err := m.instance(ctx, tableName, dbName) + if err != nil { + return nil, ctx, err + } + + t := tableQuery{ + storage: instance.Storage, + mapper: m.TableMapper, + table: tableName, + data: data, + row: row, + vars: instance.vars, + } + + if t.data != nil { + t.colNames = data[0] + t.skipWhereCols = make([]string, 0, len(t.colNames)) + t.postCheck = make([]string, 0, len(t.colNames)) + } + + return &t, ctx, nil +} + +func (t *tableQuery) receiveRow(index int, row interface{}, _ []string, rawValues []string) error { + qb := t.storage.QueryBuilder(). + Select(t.colNames...). + From(t.table) + + eq := t.storage.WhereEq(row, sqluct.Columns(t.colNames...)) + + for _, sk := range t.skipWhereCols { + delete(eq, sk) + } + + t.skipWhereCols = t.skipWhereCols[:0] + + for _, col := range t.colNames { + if _, ok := eq[col]; !ok { + continue + } + + qb = qb.Where(squirrel.Eq{col: eq[col]}) + } + + dest := reflect.New(reflect.TypeOf(row).Elem()).Interface() + + err := t.storage.Select(context.Background(), qb, dest) + if err != nil { + query, args, qbErr := qb.ToSql() + if qbErr != nil { + return fmt.Errorf("failed to build query: %w", qbErr) + } + + return fmt.Errorf("failed to query row %d (%+v) with %q %v: %w", index, row, query, args, err) + } + + colOption := sqluct.Columns(t.colNames...) + + pc := t.postCheck + t.postCheck = t.postCheck[:0] + + return t.doPostCheck(t.colNames, pc, + combine(t.storage.Mapper.ColumnsValues(reflect.ValueOf(row), colOption)), + combine(t.storage.Mapper.ColumnsValues(reflect.ValueOf(dest), colOption)), + rawValues) +} + +func combine(keys []string, vals []interface{}) map[string]interface{} { + m := make(map[string]interface{}, len(keys)) + for i, k := range keys { + m[k] = vals[i] + } + + return m +} + +func (t *tableQuery) skipDecode(column, value string) bool { + // Databases do not provide JSON equality conditions in general, + // so if value looks like a non-scalar JSON it is removed from WHERE condition and checked for equality + // using Go values during post processing. + if len(value) > 0 && (value[0] == '{' || value[0] == '[') && json.Valid([]byte(value)) { + t.postCheck = append(t.postCheck, column) + t.skipWhereCols = append(t.skipWhereCols, column) + + return false + } + + // If value looks like a variable name and does not have an associated value yet, + // it is removed from decoding and WHERE condition. + if t.vars != nil && t.vars.IsVar(value) { + if _, found := t.vars.Get(value); found { + return false + } + + t.skipWhereCols = append(t.skipWhereCols, column) + + return true + } + + return false +} + +func (t *tableQuery) makeReplaces(onSetErr *error) (map[string]string, error) { + replaces := make(map[string]string) + + if t.vars == nil { + return nil, nil + } + + if vars := t.vars.GetAll(); len(vars) > 0 { + replaces = make(map[string]string, len(vars)) + + for k, v := range vars { + s, err := t.mapper.Encode(v) + if err != nil { + return nil, err + } + + replaces[k] = s + } + } + + t.vars.OnSet(func(key string, val interface{}) { + s, err := t.mapper.Encode(val) + if err != nil { + *onSetErr = err + } + + replaces[key] = s + }) + + return replaces, nil +} + +func (m *Manager) assertRows(ctx context.Context, tableName, dbName string, data [][]string, exhaustiveList bool) (_ context.Context, err error) { + t, ctx, err := m.makeTableQuery(ctx, tableName, dbName, data) + if err != nil { + return ctx, err + } + + defer func() { + // Expose table contents to simplify test debugging. + if err != nil { + err = t.exposeContents(err) + } + }() + + if exhaustiveList { + err = t.checkCount(ctx) + if err != nil { + return ctx, err + } + } + + if data == nil { + return ctx, nil + } + + var onSetErr error + + replaces, err := t.makeReplaces(&onSetErr) + if err != nil { + return ctx, err + } + + // Iterating rows. + err = m.TableMapper.IterateTable(IterateConfig{ + Data: data, + Item: t.row, + SkipDecode: t.skipDecode, + Replaces: replaces, + ReceiveRow: t.receiveRow, + }) + + if err == nil && onSetErr != nil { + err = onSetErr + } + + return ctx, err +} + +func (t *tableQuery) doPostCheck(colNames []string, postCheck []string, argsExp, argsRcv map[string]interface{}, rawValues []string) error { + for i, name := range colNames { + if t.vars.IsVar(rawValues[i]) { + t.vars.Set(rawValues[i], argsRcv[name]) + } + + pc := false + + for _, col := range postCheck { + if col == name { + pc = true + + break + } + } + + if !pc { + continue + } + + te := testingT{} + + assert.Equal(&te, indirect(argsExp[name]), indirect(argsRcv[name])) + + if te.Err != nil { + return fmt.Errorf("unexpected row contents at column %s (%#v, %#v): %w", + name, indirect(argsExp[name]), indirect(argsRcv[name]), te.Err) + } + } + + return nil +} + +func indirect(v interface{}) interface{} { + rv := reflect.ValueOf(v) + for rv.Kind() == reflect.Ptr { + rv = rv.Elem() + } + + return rv.Interface() +} + +// ParseTime tries to parse time in multiple formats. +func ParseTime(s string, formats ...string) (time.Time, error) { + if len(formats) == 0 { + formats = []string{ + time.RFC3339Nano, + "2006-01-02T15:04:05.999999999", + "2006-01-02 15:04:05", + "2006-01-02", + time.RFC3339, + } + } + + var ( + t time.Time + err error + ) + + for _, f := range formats { + if t, err = time.Parse(f, s); err == nil { + return t, nil + } + } + + return t, err +} + +// NewTableMapper creates tablestruct.TableMapper with db field decoder. +func NewTableMapper() *TableMapper { + tm := &TableMapper{ + Decoder: form.NewDecoder(), + Encoder: form.NewEncoder(), + } + tm.Decoder.RegisterFunc(func(s string) (interface{}, error) { + return ParseTime(s) + }, time.Time{}) + tm.Decoder.RegisterFunc(func(s string) (interface{}, error) { + t, err := ParseTime(s) + if err != nil { + return nil, err + } + + return &t, nil + }, new(time.Time)) + + tm.Decoder.SetMode(form.ModeExplicit) + tm.Decoder.SetTagName("db") + form.RegisterSQLNullTypesDecodeFunc(tm.Decoder) + + tm.Encoder.SetMode(form.ModeExplicit) + tm.Encoder.SetTagName("db") + form.RegisterSQLNullTypesEncodeFunc(tm.Encoder, null) + + return tm +} + +var ( + errWrongType = errors.New("failed to assert type *interface{}") + errInvalidNumberOfRows = errors.New("invalid number of rows in table") + errUnknownTable = errors.New("unknown table") + errUnknownDatabase = errors.New("unknown database") +) + +func (t *tableQuery) queryExistingRows(db *sqluct.Storage, colNames []string, qb squirrel.Sqlizer) (table string, err error) { + rows, err := db.Query(context.Background(), qb) + if err != nil { + return "", err + } + + defer func() { + if closeErr := rows.Close(); closeErr != nil && err == nil { + err = closeErr + } + }() + + cols, err := rows.Columns() + if err != nil { + return "", err + } + + if len(colNames) == 0 { + colNames = cols + } + + var ( + width = map[string]int{} + res = make(map[string][]string) + ) + + for _, col := range colNames { + width[col] = len(col) + } + + cnt := 0 + + for rows.Next() { + cnt++ + + err = t.formatRow(rows, cols, width, res) + if err != nil { + return "", err + } + } + + result := t.renderRows(colNames, res, width, cnt) + + return result, rows.Err() +} + +func (t *tableQuery) renderRows(colNames []string, res map[string][]string, width map[string]int, cnt int) string { + result := "|" + + for _, col := range colNames { + if _, ok := res[col]; !ok { + continue + } + + result += " " + col + strings.Repeat(" ", width[col]-len(col)) + " |" + } + + result += "\n" + + for i := 0; i < cnt; i++ { + result += "|" + + for _, col := range colNames { + vv, ok := res[col] + if !ok { + continue + } + + v := vv[i] + result += " " + v + strings.Repeat(" ", width[col]-len(v)) + " |" + } + + result += "\n" + } + + return result +} + +func (t *tableQuery) formatRow(rows *sqlx.Rows, cols []string, width map[string]int, res map[string][]string) error { + // Create a slice of interface{} to represent each column, + // and a second slice to contain pointers to each item in the columns slice. + columns := make([]interface{}, len(cols)) + columnPointers := make([]interface{}, len(cols)) + + for i := range columns { + columnPointers[i] = &columns[i] + } + + // Scan the result into the column pointers. + if err := rows.Scan(columnPointers...); err != nil { + return err + } + + // Create map and retrieve the value for each column from the pointers slice, + // storing it in the map with the name of the column as the key. + for i, col := range cols { + val, ok := columnPointers[i].(*interface{}) + if !ok { + return fmt.Errorf("%w of %T", errWrongType, columnPointers[i]) + } + + var v string + + if *val == nil { + v = null + } else if b, ok := (*val).([]byte); ok { + v = string(b) + } else { + s, err := t.mapper.Encode(*val) + if err != nil { + return err + } + + v = s + } + + if len(v) > width[col] { + width[col] = len(v) + } + + res[col] = append(res[col], v) + } + + return nil +} diff --git a/manager_concurrency_test.go b/manager_concurrency_test.go new file mode 100644 index 0000000..90037a5 --- /dev/null +++ b/manager_concurrency_test.go @@ -0,0 +1,149 @@ +package dbsteps // nolint:testpackage + +import ( + "bytes" + "context" + "database/sql/driver" + "fmt" + "math/rand" + "testing" + "time" + + "github.com/DATA-DOG/go-sqlmock" + "github.com/bool64/sqluct" + "github.com/cucumber/godog" + "github.com/jmoiron/sqlx" + "github.com/stretchr/testify/assert" +) + +func (s *synchronized) isLocked(ctx context.Context, service string) bool { + s.mu.Lock() + defer s.mu.Unlock() + + lock := s.locks[service] + + return lock != nil && lock != ctx.Value(s.ctxKey).(chan struct{}) +} + +func TestNewManager_concurrent(t *testing.T) { + dbm := NewManager() + + db1, mock1, err := sqlmock.New() + assert.NoError(t, err) + db2, mock2, err := sqlmock.New() + assert.NoError(t, err) + db3, mock3, err := sqlmock.New() + assert.NoError(t, err) + + mock1.ExpectExec(`DELETE FROM t1`). + WillReturnResult(driver.ResultNoRows) + mock2.ExpectExec(`DELETE FROM t2`). + WillReturnResult(driver.ResultNoRows) + mock3.ExpectExec(`DELETE FROM t3`). + WillReturnResult(driver.ResultNoRows) + + dbm.Instances = map[string]Instance{ + "db1": { + Storage: sqluct.NewStorage(sqlx.NewDb(db1, "sqlmock")), + Tables: map[string]interface{}{"t1": nil}, + }, + "db2": { + Storage: sqluct.NewStorage(sqlx.NewDb(db2, "sqlmock")), + Tables: map[string]interface{}{"t2": nil}, + }, + "db3": { + Storage: sqluct.NewStorage(sqlx.NewDb(db3, "sqlmock")), + Tables: map[string]interface{}{"t3": nil}, + }, + } + + suite := godog.TestSuite{ + ScenarioInitializer: func(s *godog.ScenarioContext) { + dbm.RegisterSteps(s) + s.Step(`^I should not be blocked for "([^"]*)"$`, func(ctx context.Context, key string) error { + if dbm.sync.isLocked(ctx, key) { + return fmt.Errorf("%s is locked", key) + } + + return nil + }) + s.Step("^I sleep$", func() { + time.Sleep(time.Millisecond * time.Duration(rand.Int63n(100))) + }) + }, + Options: &godog.Options{ + Format: "pretty", + Strict: true, + Paths: []string{"_testdata/DatabaseConcurrent.feature"}, + Concurrency: 10, + }, + } + + if suite.Run() != 0 { + t.Fatal("test failed") + } +} + +func TestNewManager_concurrent_blocked(t *testing.T) { + dbm := NewManager() + + db1, mock1, err := sqlmock.New() + assert.NoError(t, err) + db2, mock2, err := sqlmock.New() + assert.NoError(t, err) + db3, mock3, err := sqlmock.New() + assert.NoError(t, err) + + mock1.ExpectExec(`DELETE FROM t1`). + WillReturnResult(driver.ResultNoRows) + mock2.ExpectExec(`DELETE FROM t2`). + WillReturnResult(driver.ResultNoRows) + mock3.ExpectExec(`DELETE FROM t3`). + WillReturnResult(driver.ResultNoRows) + + dbm.Instances = map[string]Instance{ + "db1": { + Storage: sqluct.NewStorage(sqlx.NewDb(db1, "sqlmock")), + Tables: map[string]interface{}{"t1": nil}, + }, + "db2": { + Storage: sqluct.NewStorage(sqlx.NewDb(db2, "sqlmock")), + Tables: map[string]interface{}{"t2": nil}, + }, + "db3": { + Storage: sqluct.NewStorage(sqlx.NewDb(db3, "sqlmock")), + Tables: map[string]interface{}{"t3": nil}, + }, + } + + out := bytes.Buffer{} + + suite := godog.TestSuite{ + ScenarioInitializer: func(s *godog.ScenarioContext) { + dbm.RegisterSteps(s) + s.Step(`^I should not be blocked for "([^"]*)"$`, func(ctx context.Context, key string) error { + if dbm.sync.isLocked(ctx, key) { + return fmt.Errorf("%s is locked", key) + } + + return nil + }) + s.Step("^I sleep$", func() { + time.Sleep(time.Millisecond * time.Duration(rand.Int63n(100))) + }) + }, + Options: &godog.Options{ + Output: &out, + Format: "pretty", + Strict: true, + Paths: []string{"_testdata/DatabaseConcurrentBlocked.feature"}, + Concurrency: 10, + }, + } + + if suite.Run() != 1 { + t.Fatal("test failed") + } + + assert.Contains(t, out.String(), "db1::t1 is locked") +} diff --git a/manager_test.go b/manager_test.go new file mode 100644 index 0000000..cc31e06 --- /dev/null +++ b/manager_test.go @@ -0,0 +1,376 @@ +package dbsteps_test + +import ( + "bytes" + "database/sql" + "database/sql/driver" + "testing" + "time" + + "github.com/DATA-DOG/go-sqlmock" + "github.com/bool64/sqluct" + "github.com/cucumber/godog" + "github.com/godogx/dbsteps" + "github.com/jmoiron/sqlx" + "github.com/stretchr/testify/assert" +) + +func mustParseTime(value string) time.Time { + var ( + t time.Time + err error + ) + + for _, layout := range []string{time.RFC3339, time.RFC3339Nano, "2006-01-02", "2006-01-02 15:04:05"} { + t, err = time.Parse(layout, value) + if err == nil { + break + } + } + + if err != nil { + panic(err) + } + + return t +} + +func TestManager_RegisterContext(t *testing.T) { + type RowKey struct { + Foo *string `db:"foo"` + Bar sql.NullString `db:"bar"` + } + + type row struct { + ID int `db:"id"` + RowKey + CreatedAt time.Time `db:"created_at"` + DeletedAt *time.Time `db:"deleted_at"` + } + + dbm := dbsteps.NewManager() + db, mock, err := sqlmock.New() + assert.NoError(t, err) + + dbm.Instances = map[string]dbsteps.Instance{ + "my_db": { + Storage: sqluct.NewStorage(sqlx.NewDb(db, "sqlmock")), + Tables: map[string]interface{}{ + "my_table": new(row), + "my_another_table": new(row), + }, + }, + } + + // Given there are no rows in table "my_table" of database "my_db" + 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 | + 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", + ). + WillReturnResult(driver.ResultNoRows) + + // Then only these rows are available 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.ExpectQuery(`SELECT COUNT\(1\) AS c FROM my_table`).WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(3)) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE bar = \$1 AND created_at = \$2 AND deleted_at IS NULL`). + WithArgs( + "abc", mustParseTime("2021-01-01T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(1, "foo-1", "abc", mustParseTime("2021-01-01T00:00:00Z"), nil)) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE foo = \$1 AND bar = \$2 AND created_at = \$3 AND deleted_at = \$4`). + WithArgs( + "foo-1", "def", mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(2, "foo-1", "def", mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"))) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE foo = \$1 AND bar = \$2 AND created_at = \$3 AND deleted_at = \$4`). + WithArgs( + "foo-2", "hij", mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(3, "foo-2", "hij", mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"))) + + // Assertion with interpolated variables. + // Then only these rows are available in table "my_table" of database "my_db": + // | id | foo | bar | created_at | deleted_at | + // | | foo-1 | abc | 2021-01-01T00:00:00Z | NULL | + // | | foo-1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | + // | | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | + mock.ExpectQuery(`SELECT COUNT\(1\) AS c FROM my_table`).WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(3)) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE id = \$1 AND foo = \$2 AND bar = \$3 AND created_at = \$4 AND deleted_at IS NULL`). + WithArgs( + 1, "foo-1", "abc", mustParseTime("2021-01-01T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(1, "foo-1", "abc", mustParseTime("2021-01-01T00:00:00Z"), nil)) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE id = \$1 AND foo = \$2 AND bar = \$3 AND created_at = \$4 AND deleted_at = \$5`). + WithArgs( + 2, "foo-1", "def", mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(2, "foo-1", "def", mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"))) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE id = \$1 AND foo = \$2 AND bar = \$3 AND created_at = \$4 AND deleted_at = \$5`). + WithArgs( + 3, "foo-2", "hij", mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(3, "foo-2", "hij", mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"))) + + // And no rows are available in table "my_another_table" of database "my_db" + mock.ExpectQuery(`SELECT COUNT\(1\) AS c FROM my_another_table`).WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(0)) + + buf := bytes.NewBuffer(nil) + + suite := godog.TestSuite{ + Name: "DatabaseContext", + TestSuiteInitializer: nil, + ScenarioInitializer: func(s *godog.ScenarioContext) { + dbm.RegisterSteps(s) + }, + Options: &godog.Options{ + Format: "pretty", + Output: buf, + Paths: []string{"_testdata/Database.feature"}, + Strict: true, + Randomize: time.Now().UTC().UnixNano(), + }, + } + status := suite.Run() + + if status != 0 { + t.Fatal(buf.String()) + } +} + +func TestManager_RegisterContext_fail(t *testing.T) { + type RowKey struct { + Foo string `db:"foo"` + Bar sql.NullString `db:"bar"` + } + + type row struct { + ID int `db:"id"` + RowKey + CreatedAt time.Time `db:"created_at"` + DeletedAt *time.Time `db:"deleted_at"` + } + + dbm := dbsteps.NewManager() + db, mock, err := sqlmock.New() + assert.NoError(t, err) + + dbm.Instances = map[string]dbsteps.Instance{ + "my_db": { + Storage: sqluct.NewStorage(sqlx.NewDb(db, "sqlmock")), + Tables: map[string]interface{}{ + "my_table": new(row), + }, + }, + } + + mock.ExpectQuery(`SELECT COUNT\(1\) AS c FROM my_table`).WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(2)) + + createdAt := time.Date(2020, 1, 1, 1, 1, 1, 1, time.UTC) + + mock.ExpectQuery(`SELECT id, created_at, deleted_at, foo, bar FROM my_table LIMIT 50`). + WillReturnRows(sqlmock.NewRows([]string{"id", "created_at", "deleted_at", "foo", "bar"}). + AddRow(1, createdAt, nil, "my-foo", "bar-1"). + AddRow(2, createdAt, nil, "my-foo", "bar-122")) + + buf := bytes.NewBuffer(nil) + + suite := godog.TestSuite{ + Name: "DatabaseContext", + TestSuiteInitializer: nil, + ScenarioInitializer: func(s *godog.ScenarioContext) { + dbm.RegisterSteps(s) + }, + Options: &godog.Options{ + Format: "pretty", + Output: buf, + Paths: []string{"_testdata/DatabaseFail.feature"}, + Strict: true, + }, + } + status := suite.Run() + + assert.Contains(t, buf.String(), ` +| id | foo | bar | created_at | deleted_at | +| 1 | my-foo | bar-1 | 2020-01-01T01:01:01.000000001Z | NULL | +| 2 | my-foo | bar-122 | 2020-01-01T01:01:01.000000001Z | NULL | +`) + + if status == 0 { + t.Fatal(buf.String()) + } +} + +func TestManager_RegisterContext_default(t *testing.T) { + type RowKey struct { + Foo *string `db:"foo"` + Bar sql.NullString `db:"bar"` + } + + type row struct { + ID int `db:"id"` + RowKey + CreatedAt time.Time `db:"created_at"` + DeletedAt *time.Time `db:"deleted_at"` + } + + dbm := dbsteps.NewManager() + db, mock, err := sqlmock.New() + assert.NoError(t, err) + + dbm.Instances = map[string]dbsteps.Instance{ + "default": { + Storage: sqluct.NewStorage(sqlx.NewDb(db, "sqlmock")), + Tables: map[string]interface{}{ + "my_table": new(row), + "my_another_table": new(row), + }, + PostCleanup: map[string][]string{ + "my_table": {"RESET SEQUENCE"}, + }, + }, + } + + // Given there are no rows in table "my_table" + mock.ExpectExec(`DELETE FROM my_table`). + WillReturnResult(driver.ResultNoRows) + + // PostCleanup raw statement. + mock.ExpectExec(`RESET SEQUENCE`). + WillReturnResult(driver.ResultNoRows) + + // And rows from this file are stored in table "my_table" + // """ + // _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": + // | id | foo | bar | created_at | deleted_at | + // | 1 | foo-1 | abc | 2021-01-01T00:00:00Z | NULL | + 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", + ). + WillReturnResult(driver.ResultNoRows) + + // Then only these rows are available in table "my_table": + // | 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.ExpectQuery(`SELECT COUNT\(1\) AS c FROM my_table`).WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(3)) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE bar = \$1 AND created_at = \$2 AND deleted_at IS NULL`). + WithArgs( + "abc", mustParseTime("2021-01-01T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(1, "foo-1", "abc", mustParseTime("2021-01-01T00:00:00Z"), nil)) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE foo = \$1 AND bar = \$2 AND created_at = \$3 AND deleted_at = \$4`). + WithArgs( + "foo-1", "def", mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(2, "foo-1", "def", mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"))) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE foo = \$1 AND bar = \$2 AND created_at = \$3 AND deleted_at = \$4`). + WithArgs( + "foo-2", "hij", mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(3, "foo-2", "hij", mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"))) + + // Assertion with interpolated variables. + // Then only these rows are available in table "my_table": + // | id | foo | bar | created_at | deleted_at | + // | | foo-1 | abc | 2021-01-01T00:00:00Z | NULL | + // | | foo-1 | def | 2021-01-02T00:00:00Z | 2021-01-03T00:00:00Z | + // | | foo-2 | hij | 2021-01-03T00:00:00Z | 2021-01-03T00:00:00Z | + mock.ExpectQuery(`SELECT COUNT\(1\) AS c FROM my_table`).WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(3)) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE id = \$1 AND foo = \$2 AND bar = \$3 AND created_at = \$4 AND deleted_at IS NULL`). + WithArgs( + 1, "foo-1", "abc", mustParseTime("2021-01-01T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(1, "foo-1", "abc", mustParseTime("2021-01-01T00:00:00Z"), nil)) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE id = \$1 AND foo = \$2 AND bar = \$3 AND created_at = \$4 AND deleted_at = \$5`). + WithArgs( + 2, "foo-1", "def", mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(2, "foo-1", "def", mustParseTime("2021-01-02T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"))) + + mock.ExpectQuery(`SELECT .+ FROM my_table WHERE id = \$1 AND foo = \$2 AND bar = \$3 AND created_at = \$4 AND deleted_at = \$5`). + WithArgs( + 3, "foo-2", "hij", mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"), + ). + WillReturnRows(sqlmock.NewRows([]string{"id", "foo", "bar", "created_at", "deleted_at"}). + AddRow(3, "foo-2", "hij", mustParseTime("2021-01-03T00:00:00Z"), mustParseTime("2021-01-03T00:00:00Z"))) + + // And no rows are available in table "my_another_table" + mock.ExpectQuery(`SELECT COUNT\(1\) AS c FROM my_another_table`).WillReturnRows(sqlmock.NewRows([]string{"c"}).AddRow(0)) + + buf := bytes.NewBuffer(nil) + + suite := godog.TestSuite{ + Name: "DatabaseContext", + TestSuiteInitializer: nil, + ScenarioInitializer: func(s *godog.ScenarioContext) { + dbm.RegisterSteps(s) + }, + Options: &godog.Options{ + Format: "pretty", + Output: buf, + Paths: []string{"_testdata/DatabaseDefault.feature"}, + Strict: true, + Randomize: time.Now().UTC().UnixNano(), + }, + } + status := suite.Run() + + if status != 0 { + t.Fatal(buf.String()) + } +} diff --git a/run_me.sh b/run_me.sh deleted file mode 100755 index 42e0530..0000000 --- a/run_me.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash -set -e - -# Init script to kick-start your project -url=$(git remote get-url origin) - -url_nopro=${url#*//} -url_noatsign=${url_nopro#*@} - -gh_repo=${url_noatsign#"github.com:"} -gh_repo=${gh_repo#"github.com/"} -gh_repo=${gh_repo%".git"} - -copyright="$(date +%Y) $(git config user.name)" -project_name=$(basename $gh_repo) - -echo "## Replacing all go-template references by $project_name" -find . -type f -not -name run_me.sh -print0 | xargs -0 perl -i -pe "s|2021 bool64|$copyright|g" -find . -type f -not -name run_me.sh -print0 | xargs -0 perl -i -pe "s|bool64/go-template|$gh_repo|g" -find . -type f -not -name run_me.sh -print0 | xargs -0 perl -i -pe "s|go-template|$project_name|g" - -echo "## Removing this script" -rm ./run_me.sh - -echo "## Please check the @TODO's:" -git grep TODO | grep -v run_me.sh - diff --git a/sync.go b/sync.go new file mode 100644 index 0000000..f8516de --- /dev/null +++ b/sync.go @@ -0,0 +1,116 @@ +package dbsteps + +import ( + "context" + "errors" + "strings" + "sync" + + "github.com/cucumber/godog" +) + +type sentinelError string + +// Error returns the error message. +func (e sentinelError) Error() string { + return string(e) +} + +const errMissingScenarioLock = sentinelError("missing scenario lock key in context") + +// synchronized keeps exclusive access to the scenario steps. +type synchronized struct { + mu sync.Mutex + locks map[string]chan struct{} + onRelease func(lockName string) error + ctxKey *struct{ _ int } +} + +func newSynchronized(onRelease func(lockName string) error) *synchronized { + return &synchronized{ + locks: make(map[string]chan struct{}), + onRelease: onRelease, + ctxKey: new(struct{ _ int }), + } +} + +// acquireLock acquires resource lock for the given key and returns true. +// +// If the lock is already held by another context, it waits for the lock to be released. +// It returns false is the lock is already held by this context. +// This function fails if the context is missing current lock. +func (s *synchronized) acquireLock(ctx context.Context, lockName string) (bool, error) { + currentLock, ok := ctx.Value(s.ctxKey).(chan struct{}) + if !ok { + return false, errMissingScenarioLock + } + + s.mu.Lock() + lock := s.locks[lockName] + + if lock == nil { + if s.locks == nil { + s.locks = make(map[string]chan struct{}) + } + + s.locks[lockName] = currentLock + } + + s.mu.Unlock() + + // Wait for the alien lock to be released. + if lock != nil && lock != currentLock { + <-lock + + return s.acquireLock(ctx, lockName) + } + + if lock == nil { + return true, nil + } + + return false, nil +} + +// register adds hooks to scenario context. +func (s *synchronized) register(sc *godog.ScenarioContext) { + sc.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) { + lock := make(chan struct{}) + + // Adding unique pointer to context to avoid collisions. + return context.WithValue(ctx, s.ctxKey, lock), nil + }) + + sc.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) { + s.mu.Lock() + defer s.mu.Unlock() + + // Releasing locks owned by scenario. + currentLock, ok := ctx.Value(s.ctxKey).(chan struct{}) + if !ok { + return ctx, errMissingScenarioLock + } + + var errs []string + + for key, lock := range s.locks { + if lock == currentLock { + delete(s.locks, key) + } + + if s.onRelease != nil { + if err := s.onRelease(key); err != nil { + errs = append(errs, err.Error()) + } + } + } + + close(currentLock) + + if len(errs) > 0 { + return ctx, errors.New(strings.Join(errs, ", ")) // nolint:goerr113 + } + + return ctx, nil + }) +} diff --git a/table.go b/table.go new file mode 100644 index 0000000..0bce71e --- /dev/null +++ b/table.go @@ -0,0 +1,164 @@ +package dbsteps + +import ( + "errors" + "fmt" + "reflect" + "strings" + + "github.com/swaggest/form/v5" +) + +const null = "NULL" + +// TableMapper maps data from Go value to string and back. +type TableMapper struct { + Decoder *form.Decoder + Encoder *form.Encoder +} + +func isNil(v interface{}) bool { + if v == nil { + return true + } + + rv := reflect.ValueOf(v) + if rv.Kind() == reflect.Ptr && rv.IsZero() { + return true + } + + return false +} + +// Encode converts Go value to string. +func (m *TableMapper) Encode(v interface{}) (string, error) { + if m.Encoder == nil { + m.Encoder = form.NewEncoder() + } + + if isNil(v) { + return null, nil + } + + vv, err := m.Encoder.Encode(v) + if err != nil { + return "", fmt.Errorf("failed to stringify variable value of type %T: %w", v, err) + } + + return vv[""][0], nil +} + +// SliceFromTable creates a slice from gherkin table, item type is used as slice element type. +func (m *TableMapper) SliceFromTable(data [][]string, item interface{}) (interface{}, error) { + itemType := reflect.TypeOf(item) + if itemType == nil { + return nil, errNilItemStruct + } + + if itemType.Kind() == reflect.Ptr { + itemType = itemType.Elem() + } + + result := reflect.MakeSlice(reflect.SliceOf(itemType), len(data)-1, len(data)-1) + + err := m.IterateTable(IterateConfig{ + Data: data, Item: item, + ReceiveRow: func(index int, row interface{}, colNames []string, rawValues []string) error { + result.Index(index).Set(reflect.Indirect(reflect.ValueOf(row))) + + return nil + }, + }) + if err != nil { + return nil, err + } + + return result.Interface(), nil +} + +// IterateConfig controls behavior of TableMapper.IterateTable. +type IterateConfig struct { + Data [][]string + SkipDecode func(column, value string) bool + Item interface{} + Replaces map[string]string + ReceiveRow func(index int, row interface{}, colNames []string, rawValues []string) error +} + +var ( + errNilItemStruct = errors.New("nil item struct received") + errRowRequired = errors.New("header and at least one row required in table") +) + +func itemType(v interface{}) (reflect.Type, error) { + itemType := reflect.TypeOf(v) + if itemType == nil { + return nil, errNilItemStruct + } + + if itemType.Kind() == reflect.Ptr { + itemType = itemType.Elem() + } + + return itemType, nil +} + +// IterateTable walks gherkin table calling row receiver with mapped row. +// If receiver returns error iteration stops and error is propagated. +func (m *TableMapper) IterateTable(c IterateConfig) error { + if m.Decoder == nil { + m.Decoder = form.NewDecoder() + } + + if len(c.Data) < 2 { + return errRowRequired + } + + colNames := c.Data[0] + + itemType, err := itemType(c.Item) + if err != nil { + return err + } + + values := make(map[string][]string, len(colNames)) + + for rowIndex, row := range c.Data[1:] { + itemBuf := reflect.New(itemType) + raw := make([]string, 0, len(colNames)) + + for i, cell := range row { + raw = append(raw, cell) + + if c.SkipDecode != nil && c.SkipDecode(colNames[i], cell) { + continue + } + + cell = strings.TrimSuffix(cell, "::string") + + if v, found := c.Replaces[cell]; found { + cell = v + } + + if cell != null { + values[colNames[i]] = []string{cell} + } else { + delete(values, colNames[i]) + } + } + + val := itemBuf.Interface() + + err := m.Decoder.Decode(val, values) + if err != nil { + return err + } + + err = c.ReceiveRow(rowIndex, itemBuf.Interface(), colNames, raw) + if err != nil { + return err + } + } + + return nil +} diff --git a/table_test.go b/table_test.go new file mode 100644 index 0000000..7980ecc --- /dev/null +++ b/table_test.go @@ -0,0 +1,65 @@ +package dbsteps_test + +import ( + "testing" + "time" + + "github.com/godogx/dbsteps" + "github.com/stretchr/testify/assert" + "github.com/swaggest/form/v5" +) + +func TestMapper_SliceFromTable(t *testing.T) { + type Emb struct { + B string `db:"b"` + Map map[string]int `db:"m"` + } + + type item struct { + A int `db:"a"` + Emb + } + + data := [][]string{ + {"a", "b"}, + {"1", "b1"}, + {"2", "b2"}, + } + + m := &dbsteps.TableMapper{ + Decoder: form.NewDecoder(), + } + m.Decoder.SetTagName("db") + res, err := m.SliceFromTable(data, new(item)) + assert.NoError(t, err) + + result, ok := res.([]item) + assert.True(t, ok) + assert.Len(t, result, 2) + assert.Equal(t, 1, result[0].A) + assert.Equal(t, "b1", result[0].B) + assert.Equal(t, 2, result[1].A) + assert.Equal(t, "b2", result[1].B) +} + +func TestTableMapper_Encode(t *testing.T) { + tm := dbsteps.TableMapper{} + + for _, tc := range []struct { + v interface{} + s string + }{ + {"abc", "abc"}, + {123, "123"}, + {123.45, "123.45"}, + {nil, "NULL"}, + {(*time.Time)(nil), "NULL"}, + {time.Time{}, "0001-01-01T00:00:00Z"}, + {&time.Time{}, "0001-01-01T00:00:00Z"}, + {new(int), "0"}, + } { + s, err := tm.Encode(tc.v) + assert.NoError(t, err) + assert.Equal(t, tc.s, s) + } +}