support xml

This commit is contained in:
Ming Deng
2020-08-31 13:57:26 +00:00
parent f4f200cf04
commit 087399c44a
2 changed files with 81 additions and 4 deletions

View File

@@ -15,10 +15,13 @@
package xml
import (
"context"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/astaxie/beego/pkg/infrastructure/config"
)
@@ -120,8 +123,36 @@ func TestXML(t *testing.T) {
t.Fatal(err)
}
res, _ := xmlconf.String(nil, "name")
res, _ := xmlconf.String(context.Background(), "name")
if res != "astaxie" {
t.Fatal("get name error")
}
sub, err := xmlconf.Sub(context.Background(), "mysection")
assert.Nil(t, err)
assert.NotNil(t, sub)
name, err := sub.String(context.Background(), "name")
assert.Nil(t, err)
assert.Equal(t, "MySection", name)
id, err := sub.Int(context.Background(), "id")
assert.Nil(t, err)
assert.Equal(t, 1, id)
sec := &Section{}
err = sub.Unmarshaler(context.Background(), "", sec)
assert.Nil(t, err)
assert.Equal(t, "MySection", sec.Name)
sec = &Section{}
err = xmlconf.Unmarshaler(context.Background(), "mysection", sec)
assert.Nil(t, err)
assert.Equal(t, "MySection", sec.Name)
}
type Section struct {
Name string `xml:"name"`
}