From db6093b64633592e5fad2dcdeb264e88e83e1979 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Mon, 26 Nov 2018 12:34:58 +0800 Subject: [PATCH] Review: Added names to testcases and cleaned up. --- bridge/slack/helpers_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/bridge/slack/helpers_test.go b/bridge/slack/helpers_test.go index 1226507a..b3b1fafa 100644 --- a/bridge/slack/helpers_test.go +++ b/bridge/slack/helpers_test.go @@ -7,22 +7,23 @@ import ( ) func TestExtractTopicOrPurpose(t *testing.T) { - testcases := []struct { + testcases := map[string]struct { input string wantChangeType string wantOutput string }{ - {"@someone set channel topic: one liner", "topic", "one liner"}, - {"@someone set channel purpose: one liner", "purpose", "one liner"}, - {"@someone set channel topic: multi\nliner", "topic", "multi\nliner"}, - {"@someone cleared channel topic", "topic", ""}, - {"some unmatched message", "unknown", ""}, + "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", ""}, } - for _, tc := range testcases { + for name, tc := range testcases { gotChangeType, gotOutput := extractTopicOrPurpose(tc.input) - assert.Equal(t, tc.wantChangeType, gotChangeType) - assert.Equal(t, tc.wantOutput, gotOutput) + assert.Equal(t, tc.wantChangeType, gotChangeType, "This testcase failed: " + name) + assert.Equal(t, tc.wantOutput, gotOutput, "This testcase failed: " + name) } }