-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathxml_test.go
More file actions
43 lines (36 loc) · 1.01 KB
/
xml_test.go
File metadata and controls
43 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
package runtime
import (
"bytes"
"encoding/xml"
"net/http/httptest"
"testing"
"github.com/go-openapi/testify/v2/assert"
"github.com/go-openapi/testify/v2/require"
)
var consProdXML = `<person><name>Somebody</name><id>1</id></person>`
func TestXMLConsumer(t *testing.T) {
cons := XMLConsumer()
var data struct {
XMLName xml.Name `xml:"person"`
Name string `xml:"name"`
ID int `xml:"id"`
}
err := cons.Consume(bytes.NewBufferString(consProdXML), &data)
require.NoError(t, err)
assert.EqualT(t, "Somebody", data.Name)
assert.EqualT(t, 1, data.ID)
}
func TestXMLProducer(t *testing.T) {
prod := XMLProducer()
data := struct {
XMLName xml.Name `xml:"person"`
Name string `xml:"name"`
ID int `xml:"id"`
}{Name: "Somebody", ID: 1}
rw := httptest.NewRecorder()
err := prod.Produce(rw, data)
require.NoError(t, err)
assert.EqualT(t, consProdXML, rw.Body.String())
}