mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-23 05:08:13 -05:00
31 lines
604 B
Go
31 lines
604 B
Go
package model
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/naiba/nezha/pkg/utils"
|
|
)
|
|
|
|
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())
|
|
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)
|
|
}
|
|
}
|
|
}
|