-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc_test.go
52 lines (45 loc) · 1.06 KB
/
misc_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
package goxp
import (
"runtime"
"testing"
"github.com/stretchr/testify/require"
)
func TestFilename(t *testing.T) {
_, filename, _, _ := runtime.Caller(0)
require.Equal(t, filename, Filename())
}
func TestFileExists(t *testing.T) {
type args struct {
filename string
}
tests := [...]struct {
name string
args args
want bool
}{
{"not exists", args{"not-exists"}, false},
{"not exists", args{Filename()}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := FileExists(tt.args.filename)
require.Equalf(t, tt.want, got, "want: %v, got: %v, file:%v", tt.want, got, tt.args.filename)
})
}
}
func TestJsonRecode(t *testing.T) {
type HelloStruct struct {
Message string `json:"message"`
}
var hello HelloStruct
var helloMap = map[string]string{
"message": "world",
}
require.NoError(t, JsonRecode(&hello, helloMap))
require.Equal(t, &HelloStruct{Message: "world"}, &hello)
}
func TestReplaceExt(t *testing.T) {
filename := "hello.mp3"
got := ReplaceExt(filename, ".webm")
require.Equal(t, "hello.webm", got)
}