37 lines
688 B
Go
37 lines
688 B
Go
|
package uci
|
||
|
|
||
|
import (
|
||
|
"io/ioutil"
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/andreyvit/diff"
|
||
|
"github.com/pkg/errors"
|
||
|
)
|
||
|
|
||
|
func TestParser(t *testing.T) {
|
||
|
data, err := ioutil.ReadFile("./testdata/openwrt_22.03.2_linksys_wrt1900ac-v2_default.conf")
|
||
|
if err != nil {
|
||
|
t.Fatal(errors.WithStack(err))
|
||
|
}
|
||
|
|
||
|
uci, err := Parse(data)
|
||
|
if err != nil {
|
||
|
t.Fatal(errors.WithStack(err))
|
||
|
}
|
||
|
|
||
|
exported := uci.Export()
|
||
|
|
||
|
if e, g := string(data), exported; e != g {
|
||
|
t.Errorf("uci.Export(): %s", diff.LineDiff(e, g))
|
||
|
}
|
||
|
|
||
|
err = ioutil.WriteFile(
|
||
|
"./testdata/exported/openwrt_22.03.2_linksys_wrt1900ac-v2_default.conf",
|
||
|
[]byte(exported), os.ModePerm,
|
||
|
)
|
||
|
if err != nil {
|
||
|
t.Error(errors.WithStack(err))
|
||
|
}
|
||
|
}
|