mirror of
https://github.com/TwiN/gatus.git
synced 2024-12-22 23:02:22 +01:00
93 lines
2.4 KiB
Go
93 lines
2.4 KiB
Go
package core
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
firstCondition = Condition("[STATUS] == 200")
|
|
secondCondition = Condition("[RESPONSE_TIME] < 500")
|
|
thirdCondition = Condition("[CERTIFICATE_EXPIRATION] < 72h")
|
|
|
|
timestamp = time.Now()
|
|
|
|
testService = Service{
|
|
Name: "name",
|
|
Group: "group",
|
|
URL: "https://example.org/what/ever",
|
|
Method: "GET",
|
|
Body: "body",
|
|
Interval: 30 * time.Second,
|
|
Conditions: []*Condition{&firstCondition, &secondCondition, &thirdCondition},
|
|
Alerts: nil,
|
|
Insecure: false,
|
|
NumberOfFailuresInARow: 0,
|
|
NumberOfSuccessesInARow: 0,
|
|
}
|
|
testSuccessfulResult = Result{
|
|
Hostname: "example.org",
|
|
IP: "127.0.0.1",
|
|
HTTPStatus: 200,
|
|
body: []byte("body"),
|
|
Errors: nil,
|
|
Connected: true,
|
|
Success: true,
|
|
Timestamp: timestamp,
|
|
Duration: 150 * time.Millisecond,
|
|
CertificateExpiration: 10 * time.Hour,
|
|
ConditionResults: []*ConditionResult{
|
|
{
|
|
Condition: "[STATUS] == 200",
|
|
Success: true,
|
|
},
|
|
{
|
|
Condition: "[RESPONSE_TIME] < 500",
|
|
Success: true,
|
|
},
|
|
{
|
|
Condition: "[CERTIFICATE_EXPIRATION] < 72h",
|
|
Success: true,
|
|
},
|
|
},
|
|
}
|
|
testUnsuccessfulResult = Result{
|
|
Hostname: "example.org",
|
|
IP: "127.0.0.1",
|
|
HTTPStatus: 200,
|
|
body: []byte("body"),
|
|
Errors: []string{"error-1", "error-2"},
|
|
Connected: true,
|
|
Success: false,
|
|
Timestamp: timestamp,
|
|
Duration: 750 * time.Millisecond,
|
|
CertificateExpiration: 10 * time.Hour,
|
|
ConditionResults: []*ConditionResult{
|
|
{
|
|
Condition: "[STATUS] == 200",
|
|
Success: true,
|
|
},
|
|
{
|
|
Condition: "[RESPONSE_TIME] < 500",
|
|
Success: false,
|
|
},
|
|
{
|
|
Condition: "[CERTIFICATE_EXPIRATION] < 72h",
|
|
Success: false,
|
|
},
|
|
},
|
|
}
|
|
)
|
|
|
|
func BenchmarkServiceStatus_WithResultPagination(b *testing.B) {
|
|
service := &testService
|
|
serviceStatus := NewServiceStatus(service)
|
|
for i := 0; i < MaximumNumberOfResults; i++ {
|
|
serviceStatus.AddResult(&testSuccessfulResult)
|
|
}
|
|
for n := 0; n < b.N; n++ {
|
|
serviceStatus.WithResultPagination(1, 20)
|
|
}
|
|
b.ReportAllocs()
|
|
}
|