Total Lines | 48 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package timeago |
||
2 | |||
3 | import ( |
||
4 | "encoding/json" |
||
5 | "testing" |
||
6 | ) |
||
7 | |||
8 | func TestParseJsonIntoLang(t *testing.T) { |
||
9 | t.Run("Function returns Lang model with needed values", func(test *testing.T) { |
||
10 | res := parseLangSet("langs/ru.json") |
||
11 | |||
12 | if res.Ago != "назад" { |
||
13 | t.Errorf("Function needs to return model with value назад, but returned %v", res.Ago) |
||
14 | } |
||
15 | }) |
||
16 | } |
||
17 | |||
18 | func TestIsFilePresent(t *testing.T) { |
||
19 | t.Run("isFilePresent return false if file doesn't exist", func(test *testing.T) { |
||
20 | res, _ := isFilePresent("somerandompath") |
||
21 | |||
22 | if res { |
||
23 | t.Error("isFilePresent must return false, because filepath points to a file that doesn't exist") |
||
24 | } |
||
25 | }) |
||
26 | |||
27 | t.Run("isFilePresent return true if file exist", func(test *testing.T) { |
||
28 | ok, err := isFilePresent("timeago.go") |
||
29 | |||
30 | if err != nil { |
||
31 | t.Errorf("isFilePresent must return true, because filepath points to a file that exists, but returned error %v", err) |
||
32 | } |
||
33 | |||
34 | if !ok { |
||
35 | t.Error("isFilePresent must return true, because filepath points to a file that exists") |
||
36 | } |
||
37 | }) |
||
38 | } |
||
39 | |||
40 | func TestReadFile(t *testing.T) { |
||
41 | t.Run("readFile returns content of the file", func(test *testing.T) { |
||
42 | res := readFile("langs/en.json") |
||
43 | |||
44 | var js json.RawMessage |
||
45 | err := json.Unmarshal(res, &js) |
||
46 | |||
47 | if err != nil { |
||
48 | t.Errorf("Function readFile must return JSON object but %s returned", string(res)) |
||
49 | } |
||
52 |