-
Notifications
You must be signed in to change notification settings - Fork 28
/
fake_aiven.go
59 lines (53 loc) · 1.32 KB
/
fake_aiven.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
package fakes
import (
"net/http"
"net/http/httptest"
"fmt"
)
type FakeAivenServer struct {
Server *httptest.Server
Mux *http.ServeMux
}
func NewFakeAivenServer(validToken string) (aivenServer *FakeAivenServer) {
mux := http.NewServeMux()
mux.HandleFunc("/project/test/invoice", func(w http.ResponseWriter, r *http.Request) {
auth:= r.Header.Get("Authorization")
validTokenHeader := fmt.Sprintf("aivenv1 %s", validToken )
if auth != validTokenHeader {
w.WriteHeader(http.StatusForbidden)
} else {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`
{
"invoices": [
{
"currency": "GBP",
"download_cookie": "123456789",
"invoice_number": "2dd1-1",
"period_begin": "2018-07-01T00:00:00Z",
"period_end": "2018-07-31T23:59:59Z",
"state": "mailed",
"total_inc_vat": "76.90",
"total_vat_zero": "64.08"
},
{
"currency": "GBP",
"download_cookie": "123456790",
"invoice_number": "2dd1-2",
"period_begin": "2018-08-01T00:00:00Z",
"period_end": "2018-08-01T23:59:59Z",
"state": "estimate",
"total_inc_vat": "13.06",
"total_vat_zero": "10.88"
}
]
}
`))
}
})
return &FakeAivenServer{
Mux: mux,
Server: httptest.NewServer(mux),
}
}