mirror of
https://github.com/daeuniverse/dae.git
synced 2025-01-05 13:08:57 +07:00
51 lines
860 B
Go
51 lines
860 B
Go
|
/*
|
||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||
|
* Copyright (c) 2023, v2rayA Organization <team@v2raya.org>
|
||
|
*/
|
||
|
|
||
|
package config
|
||
|
|
||
|
import (
|
||
|
"os"
|
||
|
"path/filepath"
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestMarshal(t *testing.T) {
|
||
|
abs, err := filepath.Abs("../example.dae")
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
merger := NewMerger(abs)
|
||
|
sections, _, err := merger.Merge()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
conf1, err := New(sections)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
b, err := conf1.Marshal(2)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
t.Log(string(b))
|
||
|
// Read it again.
|
||
|
if err = os.WriteFile("/tmp/test.dae", b, 0640); err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
sections, _, err = NewMerger("/tmp/test.dae").Merge()
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
conf2, err := New(sections)
|
||
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
if !reflect.DeepEqual(conf1, conf2) {
|
||
|
t.Fatal("not equal")
|
||
|
}
|
||
|
}
|