2023-02-25 21:53:18 +07:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2024-01-04 16:28:16 +07:00
|
|
|
* Copyright (c) 2022-2024, daeuniverse Organization <dae@v2raya.org>
|
2023-02-25 21:53:18 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|