80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
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-callbacks:
|
|
- uri: "test arm callback url"
|
|
method: "POST"
|
|
- uri: "second test arm callback url"
|
|
method: "GET"
|
|
disarm-callbacks:
|
|
- uri: "test disarm callback url"
|
|
method: "POST"
|
|
- uri: "second test disarm callback url"
|
|
method: "GET"
|
|
alarm-callbacks:
|
|
- uri: "test alarm callback url"
|
|
method: "POST"
|
|
- uri: "second test alarm callback url"
|
|
method: "GET"
|
|
telegram-api-key: "test api key"
|
|
matterbridge:
|
|
- uri: test_uri_1
|
|
token: test_token_1
|
|
gateway: test_gateway_1
|
|
username: test_username_1
|
|
- uri: test_uri_2
|
|
token: test_token_2
|
|
gateway: test_gateway_2
|
|
username: test_username_2
|
|
`
|
|
|
|
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([]HttpCallbackConfig{{"test arm callback url", "POST"}, {"second test arm callback url", "GET"}},
|
|
actualConfig.ArmCallbacks)
|
|
a.ElementsMatch([]HttpCallbackConfig{{"test disarm callback url", "POST"}, {"second test disarm callback url", "GET"}},
|
|
actualConfig.DisarmCallbacks)
|
|
a.ElementsMatch([]HttpCallbackConfig{{"test alarm callback url", "POST"}, {"second test alarm callback url", "GET"}},
|
|
actualConfig.AlarmCallbacks)
|
|
a.Equal("test api key", actualConfig.TelegramApiKey)
|
|
|
|
a.Equal(actualConfig.Matterbridge[0].URI, "test_uri_1")
|
|
a.Equal(actualConfig.Matterbridge[0].Token, "test_token_1")
|
|
a.Equal(actualConfig.Matterbridge[0].Gateway, "test_gateway_1")
|
|
a.Equal(actualConfig.Matterbridge[0].Username, "test_username_1")
|
|
a.Equal(actualConfig.Matterbridge[1].URI, "test_uri_2")
|
|
a.Equal(actualConfig.Matterbridge[1].Token, "test_token_2")
|
|
a.Equal(actualConfig.Matterbridge[1].Gateway, "test_gateway_2")
|
|
a.Equal(actualConfig.Matterbridge[1].Username, "test_username_2")
|
|
}
|