nasin/config/impl_test.go

54 lines
1.1 KiB
Go
Raw Permalink Normal View History

package config
import "maps"
import "testing"
func TestDiffValueMapsNone (test *testing.T) {
str := `
thing = something
otherThing = otherValue
# comment
otherThing = true
otherThing = 234
yetAnotherThing = 0.23498
`
file1 := parseFileString(test, str)
file2 := parseFileString(test, str)
diff := diffValueMaps(file1.Map(), file2.Map())
if len(diff) != 0 {
test.Fatalf("diff not empty:\n%v", diff)
}
}
func TestDiffValueMaps (test *testing.T) {
file1 := parseFileString(test,
`key4=0
key1=value1
# comment
key2=34`)
file2 := parseFileString(test,
`key1=value2
key2=34
# comment
key3=0.2`)
diff := diffValueMaps(file1.Map(), file2.Map())
correct := map[string] struct { } {
"key1": struct { } { },
"key3": struct { } { },
"key4": struct { } { },
}
if !maps.Equal(diff, correct) {
test.Error("diffs do not match")
test.Errorf("EXPECTED:\n%v", correct)
test.Errorf("GOT:\n%v", diff)
test.Fail()
}
}
// TODO we need way more tests!
// need to test watching files. maybe make a temp dir and do it there. remember
// to defer cleaning up the dir and closing of the config.