-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
1,749 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
**/.* | ||
**/*.md | ||
**/*.MD | ||
**/*.yaml | ||
**/*.yml | ||
**/sdktest/** | ||
**/testdata/** | ||
**/*_test.go | ||
**/Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
version: '3' | ||
|
||
tasks: | ||
release:sdk:python: | ||
cmds: | ||
- task: swagger:update-version | ||
- task: git:clone:python | ||
- task: generate:sdk:python | ||
- task: test:sdk:python | ||
- task: git:commit:python | ||
- rm -rf ./dist | ||
- python3 setup.py sdist bdist_wheel | ||
- python3 -m twine upload dist/* | ||
dir: ./sdktest/python/gnomock | ||
|
||
swagger:update-version: | ||
cmds: | ||
- | | ||
sed -Ei '' 's/^ version: (.*)$/ version: {{.version}}/' swagger/swagger.yaml | ||
- | | ||
sed -Ei '' 's/^packageVersion: (.*)$/packageVersion: {{.version}}/' swagger/config/python.yaml | ||
- | | ||
sed -Ei '' 's/apis\/orlangure\/gnomock\/(.*)#/apis\/orlangure\/gnomock\/{{.version}}#/' README.md | ||
- git add README.md swagger/config/python.yaml swagger/swagger.yaml | ||
- git commit -m 'Update version to {{.version}}' | ||
silent: true | ||
dir: . | ||
var: | ||
CURRENT_BRANCH: | ||
sh: git branch --show-current | ||
preconditions: | ||
- sh: test $version | ||
msg: version is not set | ||
- sh: test "{{.CURRENT_BRANCH}}" != "master" | ||
msg: version changes cannot happen on master branch | ||
|
||
git:clone:python: | ||
cmds: | ||
- rm -rf gnomock | ||
- git clone --depth 1 https://github.com/orlangure/gnomock-python-sdk gnomock | ||
dir: ./sdktest/python | ||
|
||
generate:sdk:python: | ||
cmds: | ||
- | | ||
docker run --rm -v $PWD:/local \ | ||
openapitools/openapi-generator-cli:v4.3.1 generate \ | ||
-i /local/swagger/swagger.yaml \ | ||
-g python \ | ||
-o /local/sdktest/python/gnomock \ | ||
-c /local/swagger/config/python.yaml \ | ||
--git-user-id orlangure \ | ||
--git-repo-id gnomock-python-sdk | ||
silent: true | ||
dir: . | ||
|
||
git:commit:python: | ||
cmds: | ||
- rm .travis.yml | ||
- git add . | ||
- git commit -m 'Bump version to {{.version}}' | ||
- git push | ||
dir: ./sdktest/python/gnomock | ||
preconditions: | ||
- sh: test $version | ||
msg: version is not set | ||
|
||
test:sdk:python: | ||
cmds: | ||
- task: gnomock:run | ||
- | | ||
{{ if not .CI }} | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
{{ end }} | ||
pip3 install -r requirements.txt | ||
python3 -m pytest -n 3 -v -k TestSDK | ||
- task: gnomock:stop | ||
dir: ./sdktest/python | ||
|
||
gnomock:run: | ||
cmds: | ||
- task: gnomock:stop | ||
- task: gnomock:build:server | ||
- task: gnomock:build:cleaner | ||
- | | ||
docker run -itd --rm \ | ||
-p 23042:23042 \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-v $PWD:$PWD \ | ||
--name gnomockd_test \ | ||
gnomock | ||
dir: . | ||
|
||
gnomock:stop: | ||
cmds: | ||
- docker container stop gnomockd_test | ||
vars: | ||
ID: | ||
sh: docker container ls -q -f name=gnomockd_test | ||
status: | ||
- test -z "{{.ID}}" | ||
|
||
gnomock:build:server: | ||
env: | ||
DOCKER_BUILDKIT: "1" | ||
cmds: | ||
- docker build --progress plain --tag gnomock . | ||
dir: . | ||
|
||
gnomock:build:cleaner: | ||
env: | ||
DOCKER_BUILDKIT: "1" | ||
cmds: | ||
- docker build --progress plain --tag orlangure/gnomock-cleaner . | ||
dir: ./cmd/cleaner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
cmd/generator/templates/sdktest/python/test/test_sdk.py.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package gnomockd_test | ||
|
||
import ( | ||
"bytes" | ||
"database/sql" | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/orlangure/gnomock" | ||
"github.com/orlangure/gnomock/internal/gnomockd" | ||
_ "github.com/orlangure/gnomock/preset/cockroachdb" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCockroachDB(t *testing.T) { | ||
t.Parallel() | ||
|
||
h := gnomockd.Handler() | ||
bs, err := ioutil.ReadFile("./testdata/cockroachdb.json") | ||
require.NoError(t, err) | ||
|
||
buf := bytes.NewBuffer(bs) | ||
w, r := httptest.NewRecorder(), httptest.NewRequest(http.MethodPost, "/start/cockroachdb", buf) | ||
h.ServeHTTP(w, r) | ||
|
||
res := w.Result() | ||
|
||
defer func() { require.NoError(t, res.Body.Close()) }() | ||
|
||
body, err := ioutil.ReadAll(res.Body) | ||
require.NoError(t, err) | ||
|
||
require.Equalf(t, http.StatusOK, res.StatusCode, string(body)) | ||
|
||
var c *gnomock.Container | ||
|
||
err = json.Unmarshal(body, &c) | ||
require.NoError(t, err) | ||
|
||
connStr := fmt.Sprintf( | ||
"host=%s port=%d user=root dbname=%s sslmode=disable", | ||
c.Host, c.DefaultPort(), "gnomockd_db", | ||
) | ||
|
||
db, err := sql.Open("postgres", connStr) | ||
require.NoError(t, err) | ||
|
||
row := db.QueryRow(`select count(distinct ip_address) from customers`) | ||
count := 0 | ||
require.NoError(t, row.Scan(&count)) | ||
require.Equal(t, 1000, count) | ||
|
||
row = db.QueryRow(`select a from tbl`) | ||
value := 0 | ||
require.NoError(t, row.Scan(&value)) | ||
require.Equal(t, 42, value) | ||
|
||
row = db.QueryRow(`select max(foo) from things limit 1`) | ||
value = 0 | ||
require.NoError(t, row.Scan(&value)) | ||
require.Equal(t, 3, value) | ||
|
||
bs, err = json.Marshal(c) | ||
require.NoError(t, err) | ||
|
||
buf = bytes.NewBuffer(bs) | ||
w, r = httptest.NewRecorder(), httptest.NewRequest(http.MethodPost, "/stop", buf) | ||
h.ServeHTTP(w, r) | ||
|
||
res = w.Result() | ||
require.Equal(t, http.StatusOK, res.StatusCode) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"preset": { | ||
"queries_files": [ | ||
"./testdata/cockroachdb/customers.sql", | ||
"./testdata/cockroachdb/things.sql" | ||
], | ||
"queries": [ | ||
"create table tbl(a int)", | ||
"insert into tbl(a) values (42)" | ||
], | ||
"db": "gnomockd_db", | ||
"version": "v19.2.11" | ||
}, | ||
"options": { | ||
} | ||
} |
Oops, something went wrong.