Skip to content

Commit 3204711

Browse files
committed
feat: add tests on persistence
1 parent 2f0a267 commit 3204711

File tree

6 files changed

+81
-3
lines changed

6 files changed

+81
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ build/
55
coverage/
66
docs/.vuepress/dist/
77
node_modules/
8-
sessions/
8+
sessions
9+
!tests/sessions
910
smocker
1011
smocker.test
1112
vendor/

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ CADDY=$(GOPATH)/bin/caddy
5353
$(CADDY):
5454
cd /tmp; go get github.com/caddyserver/caddy/v2/...
5555

56+
.PHONY: persistence
57+
persistence:
58+
rm -rf ./sessions || true
59+
cp -r tests/sessions sessions
60+
5661
.PHONY: start
57-
start: $(REFLEX)
62+
start: $(REFLEX) persistence
5863
$(REFLEX) --start-service \
5964
--decoration='none' \
6065
--regex='\.go$$' \
@@ -80,7 +85,7 @@ test:
8085

8186
PID_FILE=/tmp/$(APPNAME).test.pid
8287
.PHONY: test-integration
83-
test-integration: $(VENOM) check-default-ports
88+
test-integration: $(VENOM) check-default-ports persistence
8489
mkdir -p coverage
8590
go test -race -coverpkg="./..." -c . -o $(APPNAME).test
8691
SMOCKER_PERSISTENCE_DIRECTORY=./sessions ./$(APPNAME).test -test.coverprofile=coverage/test-integration-cover.out >/dev/null 2>&1 & echo $$! > $(PID_FILE)

tests/features/0_persistence.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Persistance
2+
version: "2"
3+
testcases:
4+
- name: Check Mocks
5+
steps:
6+
- type: http
7+
method: GET
8+
url: http://localhost:8081/mocks
9+
assertions:
10+
- result.statuscode ShouldEqual 200
11+
- result.bodyjson.__len__ ShouldEqual 1
12+
- result.bodyjson.bodyjson0.state.id ShouldEqual YnJEM95SR
13+
- name: Check History
14+
steps:
15+
- type: http
16+
method: GET
17+
url: http://localhost:8081/history
18+
assertions:
19+
- result.statuscode ShouldEqual 200
20+
- result.bodyjson.__len__ ShouldEqual 1
21+
- result.bodyjson.bodyjson0.context.mock_id ShouldEqual YnJEM95SR
22+
- name: Check Sessions
23+
steps:
24+
- type: http
25+
method: GET
26+
url: http://localhost:8081/sessions
27+
assertions:
28+
- result.statuscode ShouldEqual 200
29+
- result.bodyjson.__len__ ShouldEqual 1
30+
- result.bodyjson.bodyjson0.id ShouldEqual 3giPMr5IR
31+
- result.bodyjson.bodyjson0.history.__len__ ShouldEqual 1
32+
- result.bodyjson.bodyjson0.mocks.__len__ ShouldEqual 1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
- context:
2+
mockid: YnJEM95SR
3+
mocktype: static
4+
delay: ""
5+
request:
6+
path: /test
7+
method: GET
8+
date: 2024-01-22T21:06:00.547178247+01:00
9+
response:
10+
status: 200
11+
body:
12+
message: test
13+
headers:
14+
Content-Type:
15+
- application/json
16+
date: 2024-01-22T21:06:00.547400418+01:00

tests/sessions/3giPMr5IR/mocks.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- request:
2+
path:
3+
matcher: ShouldEqual
4+
value: /test
5+
method:
6+
matcher: ShouldEqual
7+
value: GET
8+
response:
9+
body: |
10+
{"message": "test"}
11+
status: 200
12+
headers:
13+
Content-Type:
14+
- application/json
15+
context:
16+
times: 1
17+
state:
18+
id: YnJEM95SR
19+
times_count: 0
20+
locked: false
21+
creation_date: 2024-01-22T21:05:27.349554475+01:00

tests/sessions/sessions.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- id: 3giPMr5IR
2+
name: 'Session #1'
3+
date: 2024-01-22T21:05:11.838034004+01:00

0 commit comments

Comments
 (0)