2019-02-23 13:51:27 -08:00
|
|
|
package samechannel
|
2017-07-25 11:11:52 -07:00
|
|
|
|
|
|
|
import (
|
2019-02-23 13:51:27 -08:00
|
|
|
"io/ioutil"
|
2018-12-26 06:16:09 -08:00
|
|
|
"testing"
|
|
|
|
|
2017-07-25 11:11:52 -07:00
|
|
|
"github.com/42wim/matterbridge/bridge/config"
|
2019-02-23 13:51:27 -08:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-07-25 11:11:52 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2018-11-13 14:30:56 -08:00
|
|
|
const testConfig = `
|
2017-07-25 11:11:52 -07:00
|
|
|
[mattermost.test]
|
|
|
|
[slack.test]
|
|
|
|
|
|
|
|
[[samechannelgateway]]
|
|
|
|
enable = true
|
|
|
|
name = "blah"
|
|
|
|
accounts = [ "mattermost.test","slack.test" ]
|
|
|
|
channels = [ "testing","testing2","testing10"]
|
|
|
|
`
|
|
|
|
|
2018-11-13 14:30:56 -08:00
|
|
|
var (
|
|
|
|
expectedConfig = config.Gateway{
|
|
|
|
Name: "blah",
|
|
|
|
Enable: true,
|
|
|
|
In: []config.Bridge(nil),
|
|
|
|
Out: []config.Bridge(nil),
|
|
|
|
InOut: []config.Bridge{
|
|
|
|
{
|
|
|
|
Account: "mattermost.test",
|
|
|
|
Channel: "testing",
|
|
|
|
Options: config.ChannelOptions{Key: ""},
|
|
|
|
SameChannel: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Account: "mattermost.test",
|
|
|
|
Channel: "testing2",
|
|
|
|
Options: config.ChannelOptions{Key: ""},
|
|
|
|
SameChannel: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Account: "mattermost.test",
|
|
|
|
Channel: "testing10",
|
|
|
|
Options: config.ChannelOptions{Key: ""},
|
|
|
|
SameChannel: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Account: "slack.test",
|
|
|
|
Channel: "testing",
|
|
|
|
Options: config.ChannelOptions{Key: ""},
|
|
|
|
SameChannel: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Account: "slack.test",
|
|
|
|
Channel: "testing2",
|
|
|
|
Options: config.ChannelOptions{Key: ""},
|
|
|
|
SameChannel: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Account: "slack.test",
|
|
|
|
Channel: "testing10",
|
|
|
|
Options: config.ChannelOptions{Key: ""},
|
|
|
|
SameChannel: true,
|
|
|
|
},
|
|
|
|
},
|
2017-07-25 11:11:52 -07:00
|
|
|
}
|
2018-11-13 14:30:56 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetConfig(t *testing.T) {
|
2019-02-23 13:51:27 -08:00
|
|
|
logger := logrus.New()
|
|
|
|
logger.SetOutput(ioutil.Discard)
|
|
|
|
cfg := config.NewConfigFromString(logger, []byte(testConfig))
|
2017-07-25 11:11:52 -07:00
|
|
|
sgw := New(cfg)
|
|
|
|
configs := sgw.GetConfig()
|
2018-11-13 14:30:56 -08:00
|
|
|
assert.Equal(t, []config.Gateway{expectedConfig}, configs)
|
2017-07-25 11:11:52 -07:00
|
|
|
}
|