summaryrefslogtreecommitdiff
path: root/teleirc/matterbridge/bridge/slack/helpers_test.go
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-11-02 15:27:18 +0800
committerMistivia <i@mistivia.com>2025-11-02 15:27:18 +0800
commite9c24f4af7ed56760f6db7941827d09f6db9020b (patch)
tree62128c43b883ce5e3148113350978755779bb5de /teleirc/matterbridge/bridge/slack/helpers_test.go
parent58d5e7cfda4781d8a57ec52aefd02983835c301a (diff)
add matterbridge
Diffstat (limited to 'teleirc/matterbridge/bridge/slack/helpers_test.go')
-rw-r--r--teleirc/matterbridge/bridge/slack/helpers_test.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/teleirc/matterbridge/bridge/slack/helpers_test.go b/teleirc/matterbridge/bridge/slack/helpers_test.go
new file mode 100644
index 0000000..fe3ba41
--- /dev/null
+++ b/teleirc/matterbridge/bridge/slack/helpers_test.go
@@ -0,0 +1,36 @@
+package bslack
+
+import (
+ "io/ioutil"
+ "testing"
+
+ "github.com/42wim/matterbridge/bridge"
+ "github.com/sirupsen/logrus"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestExtractTopicOrPurpose(t *testing.T) {
+ testcases := map[string]struct {
+ input string
+ wantChangeType string
+ wantOutput string
+ }{
+ "success - topic type": {"@someone set channel topic: foo bar", "topic", "foo bar"},
+ "success - purpose type": {"@someone set channel purpose: foo bar", "purpose", "foo bar"},
+ "success - one line": {"@someone set channel topic: foo bar", "topic", "foo bar"},
+ "success - multi-line": {"@someone set channel topic: foo\nbar", "topic", "foo\nbar"},
+ "success - cleared": {"@someone cleared channel topic", "topic", ""},
+ "error - unhandled": {"some unmatched message", "unknown", ""},
+ }
+
+ logger := logrus.New()
+ logger.SetOutput(ioutil.Discard)
+ cfg := &bridge.Config{Bridge: &bridge.Bridge{Log: logrus.NewEntry(logger)}}
+ b := newBridge(cfg)
+ for name, tc := range testcases {
+ gotChangeType, gotOutput := b.extractTopicOrPurpose(tc.input)
+
+ assert.Equalf(t, tc.wantChangeType, gotChangeType, "This testcase failed: %s", name)
+ assert.Equalf(t, tc.wantOutput, gotOutput, "This testcase failed: %s", name)
+ }
+}