package main import ( "log" "os" "testing" "time" "git.sr.ht/~michalr/go-satel" "github.com/stretchr/testify/assert" ) const data = ` satel-addr: "test satel address" tg-chat-ids: - 1234 - 5678 - 9876 allowed-types: - "zone-isolate" - "zone-alarm" allowed-indexes: - 5678 - 1337 pool-interval: 5m arm-callback-urls: - "test arm callback url" - "second test arm callback url" disarm-callback-urls: - "test disarm callback url" - "second test disarm callback url" alarm-callback-urls: - "test alarm callback url" - "second test alarm callback url" ` func TestParseYamlConfig(t *testing.T) { a := assert.New(t) actualConfig := parseConfigFromFile([]byte(data), log.New(os.Stderr, "", log.Ltime)) a.Equal("test satel address", actualConfig.SatelAddr) a.ElementsMatch([]int64{1234, 5678, 9876}, actualConfig.ChatIds) a.ElementsMatch([]int{5678, 1337}, actualConfig.AllowedIndexes) a.ElementsMatch([]SatelChangeType{{satel.ZoneIsolate}, {satel.ZoneAlarm}}, actualConfig.AllowedTypes) a.Equal(5*time.Minute, actualConfig.PoolInterval.GetDuration()) a.ElementsMatch([]string{"test arm callback url", "second test arm callback url"}, actualConfig.ArmCallbackUrls) a.ElementsMatch([]string{"test disarm callback url", "second test disarm callback url"}, actualConfig.DisarmCallbackUrls) a.ElementsMatch([]string{"test alarm callback url", "second test alarm callback url"}, actualConfig.AlarmCallbackUrls) }