2024-03-24 17:39:12 +00:00
|
|
|
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"
|
2025-01-03 19:33:36 +00:00
|
|
|
telegram-api-key: "test api key"
|
2024-12-29 21:28:09 +00:00
|
|
|
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
|
2024-03-24 17:39:12 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
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)
|
2025-01-03 19:33:36 +00:00
|
|
|
a.Equal("test api key", actualConfig.TelegramApiKey)
|
2024-12-29 21:28:09 +00:00
|
|
|
|
|
|
|
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")
|
2024-03-24 17:39:12 +00:00
|
|
|
}
|