2020-10-27 17:17:41 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2022-08-21 20:30:07 +02:00
|
|
|
func assertEqual[S comparable](have S, want S, t *testing.T) {
|
2020-10-27 17:17:41 +01:00
|
|
|
if have != want {
|
2022-08-16 00:23:29 +02:00
|
|
|
t.Error("have:", have, ", want:", want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func assertEqualSlice[S comparable](have []S, want []S, t *testing.T) {
|
|
|
|
if len(have) != len(want) {
|
|
|
|
t.Error("lengths differ! have:", len(have), ", want:", len(want))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range want {
|
|
|
|
if have[i] != want[i] {
|
|
|
|
t.Error("slices differ at position", i, ":", have[i], "!=", want[i])
|
|
|
|
return
|
|
|
|
}
|
2020-10-27 17:17:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestConfigFromFile(t *testing.T) {
|
|
|
|
config, err := ConfigFromFile("example.conf")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-08-21 20:30:07 +02:00
|
|
|
assertEqual(config.Port, 4711, t)
|
2023-09-04 18:16:09 +02:00
|
|
|
assertEqual(config.LinkPrefix, "https://yaf.example.com/", t)
|
|
|
|
assertEqual(config.FileDir, "/var/www/yaf/", t)
|
2022-08-21 20:30:07 +02:00
|
|
|
assertEqual(config.LinkLength, 5, t)
|
2022-08-16 00:23:29 +02:00
|
|
|
assertEqual(config.ScrubExif, true, t)
|
|
|
|
assertEqualSlice(config.ExifAllowedIds, []uint16{0x0112, 274}, t)
|
|
|
|
assertEqualSlice(config.ExifAllowedPaths, []string{"IFD/Orientation"}, t)
|
|
|
|
assertEqual(config.ExifAbortOnError, true, t)
|
2023-07-14 14:11:38 +02:00
|
|
|
assertEqual(config.FileExpiration, true, t)
|
2020-10-27 17:17:41 +01:00
|
|
|
}
|