Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

Viewing file on branch master

1package bslack
2
3import (
4 "io"
5 "testing"
6
7 "github.com/matterbridge-org/matterbridge/bridge"
8 "github.com/sirupsen/logrus"
9 "github.com/stretchr/testify/assert"
10)
11
12func TestExtractTopicOrPurpose(t *testing.T) {
13 testcases := map[string]struct {
14 input string
15 wantChangeType string
16 wantOutput string
17 }{
18 "success - topic type": {"@someone set channel topic: foo bar", "topic", "foo bar"},
19 "success - purpose type": {"@someone set channel purpose: foo bar", "purpose", "foo bar"},
20 "success - one line": {"@someone set channel topic: foo bar", "topic", "foo bar"},
21 "success - multi-line": {"@someone set channel topic: foo\nbar", "topic", "foo\nbar"},
22 "success - cleared": {"@someone cleared channel topic", "topic", ""},
23 "error - unhandled": {"some unmatched message", "unknown", ""},
24 }
25
26 logger := logrus.New()
27 logger.SetOutput(io.Discard)
28 cfg := &bridge.Config{Bridge: &bridge.Bridge{Log: logrus.NewEntry(logger)}}
29 b := newBridge(cfg)
30 for name, tc := range testcases {
31 gotChangeType, gotOutput := b.extractTopicOrPurpose(tc.input)
32
33 assert.Equalf(t, tc.wantChangeType, gotChangeType, "This testcase failed: %s", name)
34 assert.Equalf(t, tc.wantOutput, gotOutput, "This testcase failed: %s", name)
35 }
36}
37