forked from verge-io/govergeos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_test.go
More file actions
59 lines (52 loc) · 1.53 KB
/
Copy pathsystem_test.go
File metadata and controls
59 lines (52 loc) · 1.53 KB
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 vergeos
import (
"context"
"net/http"
"testing"
)
func TestSystemService_GetInfo(t *testing.T) {
client := newTestClient(t, apiMux(map[string]http.HandlerFunc{
"GET /version.json": func(w http.ResponseWriter, r *http.Request) {
jsonResponse(w, 200, SystemInfo{Name: "v4", Version: "4.13.1", Hash: "abc123"})
},
}))
info, err := client.System.GetInfo(context.Background())
if err != nil {
t.Fatalf("GetInfo failed: %v", err)
}
if info.Version != "4.13.1" {
t.Errorf("expected version '4.13.1', got %q", info.Version)
}
if info.Name != "v4" {
t.Errorf("expected name 'v4', got %q", info.Name)
}
if info.Hash != "abc123" {
t.Errorf("expected hash 'abc123', got %q", info.Hash)
}
}
func TestSystemService_GetVersion(t *testing.T) {
client := newTestClient(t, apiMux(map[string]http.HandlerFunc{
"GET /version.json": func(w http.ResponseWriter, r *http.Request) {
jsonResponse(w, 200, SystemInfo{Name: "v4", Version: "4.13.1"})
},
}))
version, err := client.System.GetVersion(context.Background())
if err != nil {
t.Fatalf("GetVersion failed: %v", err)
}
if version != "4.13.1" {
t.Errorf("expected '4.13.1', got %q", version)
}
}
func TestSystemService_GetInfo_ServerError(t *testing.T) {
client := newTestClient(t, apiMux(map[string]http.HandlerFunc{
"GET /version.json": func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(500)
w.Write([]byte("not json"))
},
}))
_, err := client.System.GetInfo(context.Background())
if err == nil {
t.Fatal("expected error for invalid response")
}
}