feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
133
checks/llmhttp/result_test.go
Обычный файл
133
checks/llmhttp/result_test.go
Обычный файл
@@ -0,0 +1,133 @@
|
||||
package llmhttp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/app/models"
|
||||
"rsgit.ru/rsmon/rsmon/internal/checkresult"
|
||||
)
|
||||
|
||||
func TestInfluxTags(t *testing.T) {
|
||||
c := models.Check{ID: 123}
|
||||
|
||||
r := &Result{
|
||||
CheckResult: checkresult.CheckResult{
|
||||
State: "OK",
|
||||
Error: nil,
|
||||
Warnings: nil,
|
||||
Duration: 100 * time.Millisecond,
|
||||
},
|
||||
StatusCode: 200,
|
||||
}
|
||||
|
||||
tags := r.InfluxTags(c)
|
||||
if tags["check"] != "123" {
|
||||
t.Errorf("check = %q, want 123", tags["check"])
|
||||
}
|
||||
if tags["state"] != "OK" {
|
||||
t.Errorf("state = %q, want OK", tags["state"])
|
||||
}
|
||||
if tags["code"] != "200" {
|
||||
t.Errorf("code = %q, want 200", tags["code"])
|
||||
}
|
||||
if _, ok := tags["error"]; ok {
|
||||
t.Error("error tag should not be present when Error is nil")
|
||||
}
|
||||
|
||||
rWithErr := &Result{
|
||||
CheckResult: checkresult.CheckResult{
|
||||
State: "ERR",
|
||||
Error: errors.New("something went wrong"),
|
||||
Warnings: nil,
|
||||
Duration: 100 * time.Millisecond,
|
||||
},
|
||||
StatusCode: 500,
|
||||
}
|
||||
|
||||
tags = rWithErr.InfluxTags(c)
|
||||
if tags["error"] != "something went wrong" {
|
||||
t.Errorf("error = %q, want 'something went wrong'", tags["error"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestInfluxTags_Warnings(t *testing.T) {
|
||||
c := models.Check{ID: 456}
|
||||
|
||||
r := &Result{
|
||||
CheckResult: checkresult.CheckResult{
|
||||
State: "WARN",
|
||||
Warnings: []string{"redirect detected", "slow response"},
|
||||
Duration: time.Second,
|
||||
},
|
||||
StatusCode: 301,
|
||||
}
|
||||
|
||||
tags := r.InfluxTags(c)
|
||||
wantWarnings := "redirect detected,slow response"
|
||||
if tags["warnings"] != wantWarnings {
|
||||
t.Errorf("warnings = %q, want %q", tags["warnings"], wantWarnings)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInfluxFields(t *testing.T) {
|
||||
r := &Result{
|
||||
CheckResult: checkresult.CheckResult{
|
||||
State: "OK",
|
||||
Duration: 1234 * time.Millisecond,
|
||||
},
|
||||
}
|
||||
|
||||
fields := r.InfluxFields()
|
||||
if took, ok := fields["took"]; !ok {
|
||||
t.Error("took field missing")
|
||||
} else if took != int64(1234) {
|
||||
t.Errorf("took = %v (%T), want int64(1234)", took, took)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInfluxFields_NegativeDuration(t *testing.T) {
|
||||
r := &Result{
|
||||
CheckResult: checkresult.CheckResult{
|
||||
State: "OK",
|
||||
Duration: 0,
|
||||
},
|
||||
}
|
||||
|
||||
fields := r.InfluxFields()
|
||||
if took, ok := fields["took"]; !ok {
|
||||
t.Error("took field missing")
|
||||
} else if took != int64(0) {
|
||||
t.Errorf("took = %v, want 0", took)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWarningsJoined(t *testing.T) {
|
||||
c := models.Check{ID: 1}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
warnings []string
|
||||
want string
|
||||
}{
|
||||
{"nil", nil, ""},
|
||||
{"empty", []string{}, ""},
|
||||
{"single", []string{"a"}, "a"},
|
||||
{"multiple", []string{"a", "b", "c"}, "a,b,c"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := &Result{
|
||||
CheckResult: checkresult.CheckResult{
|
||||
Warnings: tt.warnings,
|
||||
},
|
||||
}
|
||||
tags := r.InfluxTags(c)
|
||||
if tags["warnings"] != tt.want {
|
||||
t.Errorf("warnings = %q, want %q", tags["warnings"], tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user