-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathlogs_test.go
More file actions
60 lines (52 loc) · 1.96 KB
/
logs_test.go
File metadata and controls
60 lines (52 loc) · 1.96 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
60
package govultr
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestLogsServiceHandler_List(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/v2/logs", func(writer http.ResponseWriter, request *http.Request) {
response := `{"logs":[{"resource_id":"xb671a46-66ed-4dfb-b839-543f2c6c0b63","resource_type":"kubernetes","log_level":"Debug","message":"Success","timestamp":"2025-08-26T00:00:07+00:00","metadata":{"user_id":"765b8aa0-e134-4b62-88e1-22f40959ffe7","ip_address":"123.123.123.123","username":"","http_status_code":200,"method":"GET","request_path":"/v2/kubernetes/clusters/xb671a46-66ed-4dfb-b839-543f2c6c0b63/node-pools","request_body": "","query_parameters": ""}}],"meta":{"continue_time": "","returned_count":1,"unreturned_count":0,"total_count":1}}`
fmt.Fprint(writer, response)
})
logs, meta, _, err := client.Logs.List(ctx, LogsOptions{
StartTime: "2025-08-26T00:00:00Z",
EndTime: "2025-08-26T00:00:10Z",
ResourceID: "xb671a46-66ed-4dfb-b839-543f2c6c0b63",
})
if err != nil {
t.Errorf("Logs.List returned error: %v", err)
}
expectedLogs := []Log{{
ResourceID: "xb671a46-66ed-4dfb-b839-543f2c6c0b63",
ResourceType: "kubernetes",
Level: "Debug",
Message: "Success",
Timestamp: "2025-08-26T00:00:07+00:00",
Metadata: LogMetadata{
UserID: "765b8aa0-e134-4b62-88e1-22f40959ffe7",
IPAddress: "123.123.123.123",
UserName: "",
HTTPStatusCode: 200,
Method: "GET",
RequestPath: "/v2/kubernetes/clusters/xb671a46-66ed-4dfb-b839-543f2c6c0b63/node-pools",
RequestBody: "",
QueryParameters: "",
},
}}
expectedMeta := &LogsMeta{
ContinueTime: "",
ReturnedCount: 1,
UnreturnedCount: 0,
TotalCount: 1,
}
if !reflect.DeepEqual(logs, expectedLogs) {
t.Errorf("Logs.List returned %+v, expected %+v", logs, expectedLogs)
}
if !reflect.DeepEqual(meta, expectedMeta) {
t.Errorf("Logs.List meta returned %+v, expected %+v", meta, expectedMeta)
}
}