feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
187
internal/sender/get_content_test.go
Обычный файл
187
internal/sender/get_content_test.go
Обычный файл
@@ -0,0 +1,187 @@
|
||||
package sender
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/spec/factories"
|
||||
)
|
||||
|
||||
var (
|
||||
subjectExampleDown = "Не доступен test monitor"
|
||||
textBodyExampleDown = strings.TrimLeft(`
|
||||
Монитор test monitor не доступен
|
||||
|
||||
Проверки: [http].
|
||||
Ошибка: test error
|
||||
|
||||
Начало события: 03.01.2019 03:04:04
|
||||
|
||||
Недоступные проверки:
|
||||
|
||||
http - test check - URL не указан (testerr)
|
||||
`, "\n")
|
||||
)
|
||||
|
||||
var markdownBodyExampleDown = strings.TrimLeft(`
|
||||
Монитор test monitor не доступен :warning:
|
||||
|
||||
Проверки: [http].
|
||||
Ошибка: test error
|
||||
|
||||
Начало события: 03.01.2019 03:04:04
|
||||
|
||||
Недоступные проверки:
|
||||
|
||||
http - test check - URL не указан (testerr)
|
||||
`, "\n")
|
||||
|
||||
var htmlBodyExampleDown = strings.TrimLeft(`
|
||||
<h4>Монитор test monitor не доступен</h4>
|
||||
|
||||
Проверки: [http].
|
||||
<h5 style='background-color: red;'>Ошибка:</h5>
|
||||
test error
|
||||
|
||||
<div>Начало события: 03.01.2019 03:04:04</div>
|
||||
|
||||
<h5>Недоступные проверки:<h5>
|
||||
|
||||
<div>
|
||||
http - test check - URL не указан (testerr)
|
||||
</div>
|
||||
`, "\n")
|
||||
|
||||
var (
|
||||
subjectExampleUp = "Снова доступен test monitor"
|
||||
textBodyExampleUp = strings.TrimLeft(`
|
||||
Монитор test monitor снова доступен
|
||||
|
||||
Проверки:
|
||||
|
||||
http - test check - URL не указан (testerr)
|
||||
|
||||
|
||||
Он был недоступен 1 минуту по причине ошибки test error
|
||||
|
||||
Начало события: 03.01.2019 03:04:05
|
||||
Окончание события: 03.01.2019 03:05:05
|
||||
`, "\n")
|
||||
)
|
||||
|
||||
var markdownBodyExampleUp = strings.TrimLeft(`
|
||||
Монитор test monitor снова доступен :white_check_mark:
|
||||
|
||||
Проверки:
|
||||
|
||||
http - test check - URL не указан (testerr)
|
||||
|
||||
|
||||
Он был недоступен 1 минуту по причине ошибки test error
|
||||
|
||||
Начало события: 03.01.2019 03:04:05
|
||||
Окончание события: 03.01.2019 03:05:05
|
||||
`, "\n")
|
||||
|
||||
var htmlBodyExampleUp = strings.TrimLeft(`
|
||||
<h4>Монитор test monitor снова доступен</h4>.
|
||||
|
||||
<h5>Проверки:<h5>
|
||||
|
||||
<div>
|
||||
http - test check - URL не указан (testerr)
|
||||
</div>
|
||||
|
||||
|
||||
<div>Он был недоступен 1 минуту по причине ошибки <code>test error</code></div>
|
||||
|
||||
<div>Начало события: 03.01.2019 03:04:05</div>
|
||||
<div>Окончание события: 03.01.2019 03:05:05</div>
|
||||
`, "\n")
|
||||
|
||||
var (
|
||||
subjectExampleExp = "Скоро истекает test check (SSL сертификат) по test monitor"
|
||||
textBodyExampleExp = strings.TrimLeft(`
|
||||
Монитор test monitor
|
||||
03.01.2019 04:04:05 истекает test check (SSL сертификат)
|
||||
`, "\n")
|
||||
)
|
||||
|
||||
var markdownBodyExampleExp = strings.TrimLeft(`
|
||||
Монитор test monitor
|
||||
03.01.2019 04:04:05 истекает test check (SSL сертификат)
|
||||
`, "\n")
|
||||
|
||||
var htmlBodyExampleExp = strings.TrimLeft(`
|
||||
Монитор test monitor
|
||||
03.01.2019 04:04:05 истекает test check <strong>(SSL сертификат)</strong>
|
||||
`, "\n")
|
||||
|
||||
func TestGetContent(t *testing.T) {
|
||||
tn := time.Date(2019, time.January, 3, 3, 4, 5, 0, time.UTC)
|
||||
|
||||
message := factories.MessageFactory()
|
||||
|
||||
subject, textBody, markdownBody, htmlBody := GetContent(&message, tn)
|
||||
|
||||
// fmt.Println(subject.String())
|
||||
// fmt.Println(textBody.String())
|
||||
// fmt.Println(markdownBody.String())
|
||||
// fmt.Println(htmlBody.String())
|
||||
|
||||
assert.Equal(t, subjectExampleDown, subject.String(), "rendered subject should match example")
|
||||
assert.Equal(t, textBodyExampleDown, textBody.String(), "rendered textBody should match example")
|
||||
assert.Equal(t, markdownBodyExampleDown, markdownBody.String(), "rendered markdownBody should match example")
|
||||
assert.Equal(t, htmlBodyExampleDown, htmlBody.String(), "rendered htmlBody should match example")
|
||||
}
|
||||
|
||||
func TestGetContentUp(t *testing.T) {
|
||||
tn := time.Date(2019, time.January, 3, 3, 4, 5, 0, time.UTC)
|
||||
|
||||
ts := time.Date(2019, time.January, 3, 3, 4, 5, 0, time.UTC)
|
||||
te := time.Date(2019, time.January, 3, 3, 5, 5, 0, time.UTC)
|
||||
|
||||
message := factories.MessageFactory()
|
||||
message.Kind = "up"
|
||||
message.Events[0].StartTime = &ts
|
||||
message.Events[0].EndTime = &te
|
||||
|
||||
subject, textBody, markdownBody, htmlBody := GetContent(&message, tn)
|
||||
|
||||
// fmt.Println(subject.String())
|
||||
// fmt.Println(textBody.String())
|
||||
// fmt.Println(markdownBody.String())
|
||||
// fmt.Println(htmlBody.String())
|
||||
|
||||
assert.Equal(t, subjectExampleUp, subject.String(), "rendered subject should match example")
|
||||
assert.Equal(t, textBodyExampleUp, textBody.String(), "rendered textBody should match example")
|
||||
assert.Equal(t, markdownBodyExampleUp, markdownBody.String(), "rendered markdownBody should match example")
|
||||
assert.Equal(t, htmlBodyExampleUp, htmlBody.String(), "rendered htmlBody should match example")
|
||||
}
|
||||
|
||||
func TestGetContentExp(t *testing.T) {
|
||||
tn := time.Date(2019, time.January, 3, 3, 4, 5, 0, time.UTC)
|
||||
|
||||
message := factories.ExpMessageFactory()
|
||||
|
||||
in1h := tn.Add(1 * time.Hour)
|
||||
message.Check.Expires = &in1h
|
||||
message.Check.Kind = "ssl"
|
||||
|
||||
subject, textBody, _, htmlBody := GetContent(&message, tn)
|
||||
|
||||
subject, textBody, markdownBody, htmlBody := GetContent(&message, tn)
|
||||
|
||||
// fmt.Println(subject.String())
|
||||
// fmt.Println(textBody.String())
|
||||
// fmt.Println(markdownBody.String())
|
||||
// fmt.Println(htmlBody.String())
|
||||
|
||||
assert.Equal(t, subjectExampleExp, subject.String(), "rendered subject should match example")
|
||||
assert.Equal(t, textBodyExampleExp, textBody.String(), "rendered textBody should match example")
|
||||
assert.Equal(t, markdownBodyExampleExp, markdownBody.String(), "rendered markdownBody should match example")
|
||||
assert.Equal(t, htmlBodyExampleExp, htmlBody.String(), "rendered htmlBody should match example")
|
||||
}
|
||||
Ссылка в новой задаче
Block a user