-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pester.Tests.ps1
64 lines (58 loc) · 1.89 KB
/
Pester.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
BeforeAll {
# Start a Redis container
$containerId = docker run --rm -p 6379:6379 -d redis
# Start Go server and store process object
$proc = Start-Process '.\reddit-assignment.exe' -PassThru
}
Describe 'Test redis container' {
It "should respond to ping" {
$res = docker exec -it $containerId redis-cli ping
$? | Should -Be $True
$res | Should -Be 'PONG'
}
}
Describe 'Test reddit-assignment.go' {
# NB: Eventhough Pester is a framework for unit-testing Powershell code,
# it is used here for integration testing.
It "should GET /ok" {
$res = iwr 'http://localhost:5000/ok' -method GET
$res.StatusCode | Should -Be 200
$res.Content | Should -Be "gin OK"
}
It "should GET /count" {
$res = iwr 'http://localhost:5000/count' -method GET
$res.StatusCode | Should -Be 200
$res.Content | Should -Be 0
}
It "should POST /inc" {
$res = iwr 'http://localhost:5000/inc' -method POST
$res.StatusCode | Should -Be 200
$res.Content | Should -Be 1
}
It "should POST /inc" {
$res = iwr 'http://localhost:5000/inc' -method POST
$res.StatusCode | Should -Be 200
$res.Content | Should -Be 2
}
It "should POST /inc" {
$res = iwr 'http://localhost:5000/inc' -method POST
$res.StatusCode | Should -Be 200
$res.Content | Should -Be 3
}
It "should POST /dec" {
$res = iwr 'http://localhost:5000/dec' -method POST
$res.StatusCode | Should -Be 200
$res.Content | Should -Be 2
}
It "should GET /count" {
$res = iwr 'http://localhost:5000/count' -method GET
$res.StatusCode | Should -Be 200
$res.Content | Should -Be 2
}
}
AfterAll {
# Teardown the process started in BeforeAll block
$proc | Stop-Process
# Teardown the Redis container
docker stop $containerId
}