-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils_test.go
51 lines (40 loc) · 1.3 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
package timeago
import (
"encoding/json"
"testing"
)
func TestParseJsonIntoLang(t *testing.T) {
t.Run("Function returns Lang model with needed values", func(test *testing.T) {
res := parseLangSet("langs/ru.json")
if res.Ago != "назад" {
t.Errorf("Function needs to return model with value назад, but returned %v", res.Ago)
}
})
}
func TestIsFilePresent(t *testing.T) {
t.Run("isFilePresent return false if file doesn't exist", func(test *testing.T) {
res, _ := isFilePresent("somerandompath")
if res {
t.Error("isFilePresent must return false, because filepath points to a file that doesn't exist")
}
})
t.Run("isFilePresent return true if file exist", func(test *testing.T) {
ok, err := isFilePresent("timeago.go")
if err != nil {
t.Errorf("isFilePresent must return true, because filepath points to a file that exists, but returned error %v", err)
}
if !ok {
t.Error("isFilePresent must return true, because filepath points to a file that exists")
}
})
}
func TestReadFile(t *testing.T) {
t.Run("readFile returns content of the file", func(test *testing.T) {
res := readFile("langs/en.json")
var js json.RawMessage
err := json.Unmarshal(res, &js)
if err != nil {
t.Errorf("Function readFile must return JSON object but %s returned", string(res))
}
})
}