Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package langset |
||
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 | result := parseJsonIntoTrans("langs/ru.json") |
||
11 | |||
12 | if result.Ago != "назад" { |
||
13 | t.Errorf("Function needs to return model with value назад, but returned %v", result.Ago) |
||
14 | } |
||
15 | }) |
||
16 | } |
||
17 | |||
18 | func TestFileExists(t *testing.T) { |
||
19 | t.Run("fileExists return false if file doesn't exist", func(test *testing.T) { |
||
20 | result, _ := fileExists("somerandompath") |
||
21 | |||
22 | if result { |
||
23 | t.Error("Function fileExists must return false, because filepath points to a file that doesn't exist") |
||
24 | } |
||
25 | }) |
||
26 | |||
27 | t.Run("fileExists return true if file exist", func(test *testing.T) { |
||
28 | result, _ := fileExists("timeago.go") |
||
29 | |||
30 | if result == false { |
||
31 | t.Error("Function fileExists must return true, because filepath points to a file that exists") |
||
32 | } |
||
33 | }) |
||
34 | } |
||
35 | |||
36 | func TestGetFileContent(t *testing.T) { |
||
37 | t.Run("getFileContent returns content of the file", func(test *testing.T) { |
||
38 | result := getFileContent("langs/en.json") |
||
39 | |||
40 | var js json.RawMessage |
||
41 | err := json.Unmarshal(result, &js) |
||
42 | |||
43 | if err != nil { |
||
44 | t.Errorf("Function getFileContent must return JSON object but %s returned", string(result)) |
||
45 | } |
||
48 |