-
Notifications
You must be signed in to change notification settings - Fork 207
/
production_test.go
71 lines (63 loc) · 1.52 KB
/
production_test.go
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
65
66
67
68
69
70
71
package main
import (
"fmt"
"net/http"
"os"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/suite"
)
type ProductionTestSuite struct {
suite.Suite
hostIp string
}
func TestProductionTestSuite(t *testing.T) {
s := new(ProductionTestSuite)
s.hostIp = os.Getenv("ADDRESS")
suite.Run(t, s)
}
func (s *ProductionTestSuite) SetupTest() {
}
// Production
func (s ProductionTestSuite) Test_Hello_ReturnsStatus200() {
start := time.Now()
if len(os.Getenv("DURATION")) > 0 {
max, _ := strconv.ParseFloat(os.Getenv("DURATION"), 64)
minutes := float64(0)
counter := 0
for time.Since(start).Minutes() < max {
address := fmt.Sprintf("http://%s/demo/hello", s.hostIp)
resp, err := http.Get(address)
counter++
if err != nil {
msg := fmt.Sprintf("Failed on request %d with error %s", counter, err.Error())
s.Fail(msg)
break
} else if resp == nil {
msg := fmt.Sprintf("Failed on request %d with no response", counter)
s.Fail(msg)
break
} else if resp.StatusCode != 200 {
msg := fmt.Sprintf("Response status code is %d", resp.StatusCode)
s.Fail(msg)
break
}
if time.Since(start).Minutes() > minutes {
fmt.Printf("%2.0f out of %2.0f minutes passed\n", minutes, max)
minutes++
}
time.Sleep(1 * time.Second)
}
} else {
address := fmt.Sprintf("http://%s/demo/hello", s.hostIp)
resp, err := http.Get(address)
if err != nil {
s.Fail(err.Error())
} else if resp == nil {
s.Fail("Got no response")
} else {
s.Equal(200, resp.StatusCode)
}
}
}