35 lines
643 B
Go
35 lines
643 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestExamples(t *testing.T) {
|
|
var previous Config
|
|
for i, ext := range []string{"json", "yaml", "xml", "custom"} {
|
|
source := ext
|
|
if source == "custom" {
|
|
source = "json"
|
|
}
|
|
data, err := examples.ReadFile("config." + source)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
path := filepath.Join(t.TempDir(), "app."+ext)
|
|
if err = os.WriteFile(path, data, 0600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := load(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if i > 0 && !reflect.DeepEqual(previous, got) {
|
|
t.Fatal("format difference")
|
|
}
|
|
previous = got
|
|
}
|
|
}
|