-
Notifications
You must be signed in to change notification settings - Fork 37
/
search_logs_test.go
161 lines (131 loc) · 4.74 KB
/
search_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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//go:build !kubernetes
// +build !kubernetes
// We don't run this test in Kubernetes because, as of 2022-10-28, the centralized logs feature is not implemented in Kubernetes yet
//TODO remove this comments after Kubernetes implementation
package search_logs_test
import (
"context"
"github.com/kurtosis-tech/kurtosis-cli/golang_internal_testsuite/test_helpers"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/services"
"github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context"
"github.com/stretchr/testify/require"
"testing"
"time"
)
const (
testName = "search-logs"
exampleServiceNamePrefix = "search-logs-"
shouldFollowLogs = true
shouldNotFollowLogs = false
service1ServiceName services.ServiceName = exampleServiceNamePrefix + "service-1"
firstFilterText = "The data have being loaded"
secondFilterText = "Starting feature"
thirdFilterText = "pool"
matchRegexFilterStr = "Starting.*logs'"
testTimeOut = 180 * time.Second
logLine1 = "Starting feature 'centralized logs'"
logLine2 = "Starting feature 'enclave pool'"
logLine3 = "Starting feature 'enclave pool with size 2'"
logLine4 = "The data have being loaded"
milliSecondsToWaitForLogs = 300
)
var (
expectedNonExistenceServiceUuids = map[services.ServiceUUID]bool{}
service1LogLines = []string{
logLine1,
logLine2,
logLine3,
logLine4,
}
logLinesByService = map[services.ServiceName][]string{
service1ServiceName: service1LogLines,
}
doesContainTextFilterForFirstRequest = kurtosis_context.NewDoesContainTextLogLineFilter(firstFilterText)
doesContainTextFilterForSecondRequest = kurtosis_context.NewDoesContainTextLogLineFilter(secondFilterText)
doesNotContainTextFilter = kurtosis_context.NewDoesNotContainTextLogLineFilter(thirdFilterText)
doesContainMatchRegexFilter = kurtosis_context.NewDoesContainMatchRegexLogLineFilter(matchRegexFilterStr)
doesNotContainMatchRegexFilter = kurtosis_context.NewDoesNotContainMatchRegexLogLineFilter(matchRegexFilterStr)
filtersByRequest = []kurtosis_context.LogLineFilter{
*doesContainTextFilterForFirstRequest,
*doesContainTextFilterForSecondRequest,
*doesNotContainTextFilter,
*doesContainMatchRegexFilter,
*doesNotContainMatchRegexFilter,
}
expectedLogLinesByRequest = [][]string{
{
logLine4,
},
{
logLine1,
logLine2,
logLine3,
},
{
logLine1,
logLine4,
},
{
logLine1,
},
{
logLine2,
logLine3,
logLine4,
},
}
shouldFollowLogsValueByRequest = []bool{
shouldFollowLogs,
shouldNotFollowLogs,
shouldNotFollowLogs,
shouldNotFollowLogs,
shouldNotFollowLogs,
}
)
func TestSearchLogs(t *testing.T) {
ctx := context.Background()
// ------------------------------------- ENGINE SETUP ----------------------------------------------
enclaveCtx, _, destroyEnclaveFunc, err := test_helpers.CreateEnclave(t, ctx, testName)
require.NoError(t, err, "An error occurred creating an enclave")
defer func() {
err = destroyEnclaveFunc()
require.NoError(t, err, "An error occurred destroying the enclave after the test finished")
}()
// ------------------------------------- TEST SETUP ----------------------------------------------
kurtosisCtx, err := kurtosis_context.NewKurtosisContextFromLocalEngine()
require.NoError(t, err)
serviceList, err := test_helpers.AddServicesWithLogLines(ctx, enclaveCtx, logLinesByService)
require.NoError(t, err, "An error occurred adding services with log lines '%+v'", logLinesByService)
require.Equal(t, len(logLinesByService), len(serviceList))
time.Sleep(milliSecondsToWaitForLogs * time.Millisecond)
// ------------------------------------- TEST RUN -------------------------------------------------
enclaveUuid := enclaveCtx.GetEnclaveUuid()
userServiceUuids := map[services.ServiceUUID]bool{}
for _, serviceCtx := range serviceList {
serviceUuid := serviceCtx.GetServiceUUID()
userServiceUuids[serviceUuid] = true
}
expectedLogLinesByService := map[services.ServiceUUID][]string{}
for requestIndex, filter := range filtersByRequest {
for serviceUuid := range userServiceUuids {
expectedLogLinesByService[serviceUuid] = expectedLogLinesByRequest[requestIndex]
}
shouldFollowLogsOption := shouldFollowLogsValueByRequest[requestIndex]
testEvaluationErr, receivedLogLinesByService, receivedNotFoundServiceUuids := test_helpers.GetLogsResponse(
t,
ctx,
testTimeOut,
kurtosisCtx,
string(enclaveUuid),
userServiceUuids,
expectedLogLinesByService,
shouldFollowLogsOption,
&filter,
)
require.NoError(t, testEvaluationErr)
for serviceUuid := range userServiceUuids {
require.Equal(t, expectedLogLinesByRequest[requestIndex], receivedLogLinesByService[serviceUuid])
}
require.Equal(t, expectedNonExistenceServiceUuids, receivedNotFoundServiceUuids)
}
}