53 lines
1018 B
Go
53 lines
1018 B
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
type (
|
|
LogTestStruct struct {
|
|
System string `json:"system"`
|
|
Message string `json:"message"`
|
|
Error TypeError `json:"error"`
|
|
}
|
|
TypeError struct {
|
|
Code int `json:"code"`
|
|
Description string `json:"description"`
|
|
}
|
|
)
|
|
|
|
func TestGetLogFile(t *testing.T) {
|
|
s := GetLogFile("test_logs", "test")
|
|
if s == nil {
|
|
t.Error("log file is nil")
|
|
}
|
|
if err := os.RemoveAll("test_logs"); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestSendMessage(t *testing.T) {
|
|
m := &LogTestStruct{
|
|
System: "go test",
|
|
Message: "CI TEST",
|
|
Error: TypeError{Code: -112, Description: "Тестирование"},
|
|
}
|
|
// Маршим в байтики
|
|
b, err := json.Marshal(m)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if err := SendMessage("https://devtest.galamart.ru/bus/pub?topic=error&channel=error", b); err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestSetupLog(t *testing.T) {
|
|
l := SetupLog("test")
|
|
if l.Prefix() != " [test] " {
|
|
t.Error(l.Prefix())
|
|
}
|
|
}
|