Skip to content

Commit 08fae9c

Browse files
authored
Merge pull request #559 from rusq/i554
Tests for #554
2 parents d487570 + 97237cb commit 08fae9c

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

source/filestorage_test.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77
"testing"
8+
"testing/fstest"
89

910
"github.com/rusq/slackdump/v3/internal/chunk"
1011
)
@@ -99,7 +100,55 @@ func Test_fstStandard_File(t *testing.T) {
99100
want string
100101
wantErr bool
101102
}{
102-
// TODO: Add test cases.
103+
{
104+
name: "file is present in index, and in filesystem",
105+
fields: fields{
106+
fs: fstest.MapFS{
107+
"C123/attachments/F123-test.txt": {
108+
Data: []byte("test file"),
109+
Mode: 644,
110+
}},
111+
idx: map[string]string{
112+
"F123": "C123/attachments/F123-test.txt",
113+
},
114+
},
115+
args: args{
116+
id: "F123",
117+
in1: "",
118+
},
119+
want: "C123/attachments/F123-test.txt",
120+
wantErr: false,
121+
},
122+
{
123+
name: "file is present in index, but not on the filesystem",
124+
fields: fields{
125+
fs: fstest.MapFS{},
126+
idx: map[string]string{
127+
"F123": "C123/attachments/F123-test.txt",
128+
},
129+
},
130+
args: args{
131+
id: "F123",
132+
in1: "",
133+
},
134+
wantErr: true,
135+
},
136+
{
137+
name: "file is not in index",
138+
fields: fields{
139+
fs: fstest.MapFS{
140+
"C123/attachments/F123-test.txt": {
141+
Data: []byte("test file"),
142+
Mode: 644,
143+
}},
144+
idx: map[string]string{},
145+
},
146+
args: args{
147+
id: "F123",
148+
in1: "",
149+
},
150+
wantErr: true,
151+
},
103152
}
104153
for _, tt := range tests {
105154
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)