-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
55 lines (52 loc) · 1.39 KB
/
utils_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
54
55
package goldtest
import (
"testing"
)
func Test_removeSpecialCharacters(t *testing.T) {
type args struct {
path string
}
tests := []struct {
name string
path string
want string
}{
{"Clean string", "test", "test"},
{"Clean string - 1", "TeSt", "TeSt"},
{"Underscore", "test_with_underscore", "test_with_underscore"},
{"Dash", "test-with-dash", "test-with-dash"},
{"Special characters", "test!@#$%^", "test"},
{"Spaces", "test with spaces", "test_with_spaces"},
{"Slashes", "test/with/slash", "test/with/slash"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := removeSpecialCharacters(tt.path); got != tt.want {
t.Errorf("removeSpecialCharacters() = %v, want %v", got, tt.want)
}
})
}
}
func Test_writeRead(t *testing.T) {
type args struct {
fileName string
bytes []byte
}
tests := []struct {
name string
args args
wantErr bool
}{
{"Write file to directory", args{"testdir/testfile_tmp", []byte("test")}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := writeFile(tt.args.fileName, tt.args.bytes); (err != nil) != tt.wantErr {
t.Errorf("writeFile() error = %v, wantErr %v", err, tt.wantErr)
}
if b, _ := readFile(tt.args.fileName); string(b) != string(tt.args.bytes) {
t.Errorf("readFile() get wrong output = %v, want %v", string(b), string(tt.args.bytes))
}
})
}
}