-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
importer: filter out user join slack message (#5)
* importer: filter out user join slack message Signed-off-by: Artem Navoiev <tenmozes@gmail.com> * refactor a little * cleanup * rename package * cleanup * refactor * rename transporter to transport * fix cli --------- Signed-off-by: Artem Navoiev <tenmozes@gmail.com> Co-authored-by: dmitryk-dk <kozlovdmitriyy@gmail.com>
1 parent
68821eb
commit 948aa73
Showing
8 changed files
with
134 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package slack | ||
|
||
import "testing" | ||
|
||
// Test for filterOutLogMessage function | ||
func TestFilterOutLogMessage(t *testing.T) { | ||
tests := []struct { | ||
message string | ||
want bool | ||
}{ | ||
{"<@U0787V2AW9W> has joined the channel", true}, | ||
{"User message content", false}, | ||
{"Another message", false}, | ||
} | ||
for _, tt := range tests { | ||
if got := filterOutLogMessage(tt.message); got != tt.want { | ||
t.Errorf("filterOutLogMessage(%q) = %v, want %v", tt.message, got, tt.want) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package transporter | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
) | ||
|
||
// Mock implementations of Importer and Exporter for testing purposes | ||
type mockImporter struct { | ||
importFunc func(ctx context.Context, message Message) error | ||
} | ||
|
||
func (m *mockImporter) Import(ctx context.Context, message Message) error { | ||
return m.importFunc(ctx, message) | ||
} | ||
|
||
type mockExporter struct { | ||
exportFunc func(ctx context.Context, processMessage func(Message)) | ||
} | ||
|
||
func (m *mockExporter) Export(ctx context.Context, processMessage func(Message)) { | ||
m.exportFunc(ctx, processMessage) | ||
} | ||
|
||
// Test for Transport.Run method | ||
func TestProcessorRun(t *testing.T) { | ||
mockImp := &mockImporter{ | ||
importFunc: func(ctx context.Context, message Message) error { | ||
if message.Text == "test message" { | ||
return nil | ||
} | ||
return errors.New("import error") | ||
}, | ||
} | ||
mockExp := &mockExporter{ | ||
exportFunc: func(ctx context.Context, processMessage func(Message)) { | ||
processMessage(Message{Text: "test message"}) | ||
processMessage(Message{Text: "<@U0787V2AW9W> has joined the channel"}) // This should be filtered out | ||
}, | ||
} | ||
processor := New(mockExp, mockImp) | ||
ctx := context.Background() | ||
processor.Run(ctx) | ||
} | ||
|
||
// Test for Importer and Exporter interaction | ||
func TestProcessorImportError(t *testing.T) { | ||
mockImp := &mockImporter{ | ||
importFunc: func(ctx context.Context, message Message) error { | ||
return errors.New("import error") | ||
}, | ||
} | ||
mockExp := &mockExporter{ | ||
exportFunc: func(ctx context.Context, processMessage func(Message)) { | ||
processMessage(Message{Text: "test message"}) | ||
}, | ||
} | ||
processor := New(mockExp, mockImp) | ||
ctx := context.Background() | ||
processor.Run(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters