-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain_test.go
More file actions
41 lines (33 loc) · 697 Bytes
/
main_test.go
File metadata and controls
41 lines (33 loc) · 697 Bytes
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
package main
import (
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
)
func Test_main(t *testing.T) {
_, _, _, _, handler := parseFlags()
ts := httptest.NewServer(handler)
defer ts.Close()
res, err := http.Get(ts.URL + "/api/v1.0/blocks")
if err != nil {
t.Fatal(err)
}
body, err := ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
t.Fatal(err)
}
// empty array response
exp := "[]"
if res.StatusCode == 500 {
// do nothing - test server doesn't exist
// need block store to run
fmt.Println("block store is not running - test didn't execute fully")
} else {
if exp != string(body) {
t.Fatalf("Expected %s got %s", exp, body)
}
}
}