-
Notifications
You must be signed in to change notification settings - Fork 5
/
read_file_from_fs_test.go
53 lines (47 loc) · 979 Bytes
/
read_file_from_fs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package goeasyi18n
import (
"embed"
"testing"
)
//go:embed testfiles/*
var readFSTestFiles embed.FS
func TestReadFileFromFS(t *testing.T) {
tests := []struct {
filename string
expectedData string
expectedErr bool
}{
{
filename: "testfiles/test1.txt",
expectedData: "test 1",
expectedErr: false,
},
{
filename: "testfiles/test2.txt",
expectedData: "test 2",
expectedErr: false,
},
{
filename: "testfiles/not-exists.txt",
expectedData: "",
expectedErr: true,
},
}
for _, tt := range tests {
t.Run(tt.filename, func(t *testing.T) {
data, err := readFileFromFS(readFSTestFiles, tt.filename)
if tt.expectedErr {
if err == nil {
t.Errorf("expected error, got nil")
}
} else {
if err != nil {
t.Errorf("didn't expect error, got %v", err)
}
}
if string(data) != tt.expectedData {
t.Errorf("expected data %q, got %q", tt.expectedData, string(data))
}
})
}
}