fiber/utils/xml_test.go
leonklingele 167a8b5e94
🚀 Feature: Add and apply more stricter golangci-lint linting rules (#2286)
* golangci-lint: add and apply more stricter linting rules

* github: drop security workflow now that we use gosec linter inside golangci-lint

* github: use official golangci-lint CI linter

* Add editorconfig and gitattributes file
2023-01-27 09:01:37 +01:00

60 lines
1.1 KiB
Go

package utils
import (
"encoding/xml"
"testing"
)
type serversXMLStructure struct {
XMLName xml.Name `xml:"servers"`
Version string `xml:"version,attr"`
Servers []serverXMLStructure `xml:"server"`
}
type serverXMLStructure struct {
XMLName xml.Name `xml:"server"`
Name string `xml:"name"`
}
const xmlString = `<servers version="1"><server><name>fiber one</name></server><server><name>fiber two</name></server></servers>`
func Test_GolangXMLEncoder(t *testing.T) {
t.Parallel()
var (
ss = &serversXMLStructure{
Version: "1",
Servers: []serverXMLStructure{
{Name: "fiber one"},
{Name: "fiber two"},
},
}
xmlEncoder XMLMarshal = xml.Marshal
)
raw, err := xmlEncoder(ss)
AssertEqual(t, err, nil)
AssertEqual(t, string(raw), xmlString)
}
func Test_DefaultXMLEncoder(t *testing.T) {
t.Parallel()
var (
ss = &serversXMLStructure{
Version: "1",
Servers: []serverXMLStructure{
{Name: "fiber one"},
{Name: "fiber two"},
},
}
xmlEncoder XMLMarshal = xml.Marshal
)
raw, err := xmlEncoder(ss)
AssertEqual(t, err, nil)
AssertEqual(t, string(raw), xmlString)
}