nezha/model/server_test.go

31 lines
604 B
Go
Raw Permalink Normal View History

2021-02-28 10:58:04 -05:00
package model
import (
"testing"
"github.com/naiba/nezha/pkg/utils"
2021-02-28 10:58:04 -05:00
)
func TestServerMarshal(t *testing.T) {
patterns := []string{
"asd > asd",
"asd \" asd",
"asd } asd",
}
for i := 0; i < len(patterns); i++ {
server := Server{
Name: patterns[i],
Tag: patterns[i],
}
serverStr := string(server.MarshalForDashboard())
2021-02-28 10:58:04 -05:00
var serverRestore Server
if utils.Json.Unmarshal([]byte(serverStr), &serverRestore) != nil {
t.Fatalf("Error: %s", serverStr)
}
if server.Name != serverRestore.Name {
t.Fatalf("Expected %s, but got %s", server.Name, serverRestore.Name)
}
2021-02-28 10:58:04 -05:00
}
}