-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
524 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package repository | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/rusq/slack" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
file1 = &slack.File{ | ||
ID: "FILE1", | ||
Created: 0, | ||
Timestamp: slack.JSONTime(time.Date(1984, 9, 16, 15, 0, 0, 0, time.UTC).Unix()), | ||
Name: "SOKO.COM", | ||
Title: "Classic Sokoban Game, (c) 1984 Spectrum Holobyte", | ||
URLPrivateDownload: "https://archive.org/details/msdos_sokoban_1984_spectrum_holobyte", | ||
NumStars: 555, | ||
Mode: "hosted", | ||
} | ||
|
||
dbFile1, _ = NewDBFile(1, 0, "C1", "1631820000.000000", "1531820000.000000", file1) | ||
) | ||
|
||
func TestNewDBFile(t *testing.T) { | ||
type args struct { | ||
chunkID int64 | ||
idx int | ||
channelID string | ||
threadTS string | ||
parentMsgTS string | ||
file *slack.File | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *DBFile | ||
wantErr bool | ||
}{ | ||
{ | ||
"success", | ||
args{1, 42, "C1", "1631820000.000000", "1531820000.000000", file1}, | ||
&DBFile{ | ||
ID: "FILE1", | ||
ChunkID: 1, | ||
ChannelID: "C1", | ||
MessageID: ptr[int64](1531820000000000), | ||
ThreadID: ptr[int64](1631820000000000), | ||
Index: 42, | ||
Mode: "hosted", | ||
Filename: ptr("SOKO.COM"), | ||
URL: ptr("https://archive.org/details/msdos_sokoban_1984_spectrum_holobyte"), | ||
Data: must(marshal(file1)), | ||
}, | ||
false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := NewDBFile(tt.args.chunkID, tt.args.idx, tt.args.channelID, tt.args.threadTS, tt.args.parentMsgTS, tt.args.file) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("NewDBFile() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
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,45 @@ | ||
package repository | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/rusq/slack" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewDBSearchFile(t *testing.T) { | ||
type args struct { | ||
chunkID int64 | ||
n int | ||
sf *slack.File | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *DBSearchFile | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "creates a new DBSearchFile", | ||
args: args{chunkID: 42, n: 50, sf: file1}, | ||
want: &DBSearchFile{ | ||
ID: 0, // autoincrement, handled by the database. | ||
ChunkID: 42, | ||
FileID: "FILE1", | ||
Index: 50, | ||
Data: must(marshal(file1)), | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := NewDBSearchFile(tt.args.chunkID, tt.args.n, tt.args.sf) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("NewDBSearchFile() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
assert.Equal(t, tt.want, got) | ||
}) | ||
} | ||
} |
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,67 @@ | ||
package repository | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/rusq/slack" | ||
) | ||
|
||
var srchMsg1 = &slack.SearchMessage{ | ||
Type: "message", | ||
Channel: slack.CtxChannel{ | ||
ID: "C123", | ||
Name: "chur", | ||
}, | ||
User: "U123", | ||
Username: "bob", | ||
Timestamp: "1725318212.603879", | ||
Text: "Hello, world!", | ||
Permalink: "http://slackdump.slack.com/archives/C123/p1725318212603879", | ||
} | ||
|
||
func TestNewDBSearchMessage(t *testing.T) { | ||
type args struct { | ||
chunkID int64 | ||
idx int | ||
sm *slack.SearchMessage | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *DBSearchMessage | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "creates a new DBSearchMessage", | ||
args: args{ | ||
chunkID: 42, | ||
idx: 50, | ||
sm: srchMsg1, | ||
}, | ||
want: &DBSearchMessage{ | ||
ID: 0, // autoincrement, handled by the database. | ||
ChunkID: 42, | ||
ChannelID: "C123", | ||
ChannelName: ptr("chur"), | ||
TS: "1725318212.603879", | ||
Text: ptr("Hello, world!"), | ||
IDX: 50, | ||
Data: must(marshal(srchMsg1)), | ||
}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := NewDBSearchMessage(tt.args.chunkID, tt.args.idx, tt.args.sm) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("NewDBSearchMessage() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("NewDBSearchMessage() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.