-
Notifications
You must be signed in to change notification settings - Fork 5
/
logs_test.go
92 lines (80 loc) · 2.29 KB
/
logs_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package oneandone
import (
"fmt"
"strings"
"testing"
"time"
)
// /logs tests
func TestListLogs(t *testing.T) {
fmt.Println("Listing all logs...")
res, err := api.ListLogs("LAST_24H", nil, nil)
if err != nil {
t.Errorf("ListLogs failed. Error: " + err.Error())
}
if len(res) == 0 {
t.Errorf("No log found.")
}
res, err = api.ListLogs("LAST_24H", nil, nil, 1, 7, "action", "", "action,start_date,end_date")
if err != nil {
t.Errorf("ListLogs with parameter options failed. Error: " + err.Error())
return
}
if len(res) == 0 {
t.Errorf("No log found.")
}
if len(res) != 7 {
t.Errorf("Wrong number of objects per page.")
}
for index := 0; index < len(res); index += 1 {
if res[index].Status != nil || res[index].Resource != nil || res[index].User != nil {
t.Errorf("Filtering a list of logs failed.")
}
if index < len(res)-1 {
if res[index].Action > res[index+1].Action {
t.Errorf("Sorting a list of logs failed.")
}
}
}
sd, _ := time.Parse(time.RFC3339, res[len(res)/2].StartDate)
ed := sd.Add(time.Hour)
res, err = api.ListLogs("CUSTOM", &sd, &ed, 0, 0, "start_date", "", "action,start_date,end_date")
if err != nil {
t.Errorf("Getting logs in custom date range failed. Error: " + err.Error())
return
}
if len(res) > 0 {
sd1, _ := time.Parse(time.RFC3339, res[0].StartDate)
ed1, _ := time.Parse(time.RFC3339, res[len(res)-1].EndDate)
if sd1.Before(sd) || ed1.After(ed) {
t.Errorf("Getting logs in custom date range failed.")
}
}
res, err = api.ListLogs("LAST_7D", nil, nil, 0, 0, "", "CREATE", "action")
if err != nil {
t.Errorf("ListLogs with parameter options failed. Error: " + err.Error())
return
}
for _, log := range res {
if !strings.Contains(strings.ToUpper(log.Action), "CREATE") {
t.Errorf("Search parameter failed.")
}
}
// Test for error response
res, err = api.ListLogs("LAST_24H", nil, nil, 2, 5, 5)
if res != nil || err == nil {
t.Errorf("ListLogs failed to handle incorrect argument type.")
}
}
func TestGetLog(t *testing.T) {
logs, _ := api.ListLogs("LAST_24H", nil, nil, 0, 0, "", "", "id")
fmt.Printf("Getting log '%s'...\n", logs[0].Id)
log, err := api.GetLog(logs[0].Id)
if err != nil {
t.Errorf("GetLog failed. Error: " + err.Error())
return
}
if log.Id != logs[0].Id {
t.Errorf("Wrong server ID.")
}
}