forked from desnoe/go-gns3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_test.go
71 lines (60 loc) · 1.16 KB
/
server_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 gogns3
import (
"os"
"strconv"
"testing"
)
func getTestServer(t *testing.T) *Server {
hostEnv, ok := os.LookupEnv("GNS3_HOST")
if !ok {
t.Error("GNS3_HOST environement variable is not set!")
}
portEnv, ok := os.LookupEnv("GNS3_PORT")
if !ok {
t.Error("GNS3_PORT environement variable is not set!")
}
p, _ := strconv.Atoi(portEnv)
s := Server{
Host: hostEnv,
Port: p,
}
return &s
}
func TestServerOK(t *testing.T) {
s := getTestServer(t)
if s.Test() != nil {
t.Error("This server must have answered")
}
}
func TestServerKO(t *testing.T) {
if testing.Short() {
t.Skip("Skipping testing in short mode")
}
s := getTestServer(t)
if err := s.Test(); err != nil {
switch e := err.(type) {
case *ServerError:
if e.Status != 1 {
t.Error(e)
}
default:
t.Error(e)
}
}
}
func TestServerGetProjects(t *testing.T) {
s := getTestServer(t)
projects, _ := s.GetProjects()
if s.Test() != nil {
t.Errorf("%+v\n", projects)
}
}
func TestServerErrorString(t *testing.T) {
e := ServerError{
Status: 1,
Message: "Test",
}
if e.Error() != "Server error #1: Test" {
t.Error("Error string different than expected")
}
}