Passed
Push — v3.0.0 ( 368635...9e91a1 )
by Serhii
01:21
created

langset/utils_test.go   A

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 25
dl 0
loc 44
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A langset.TestFileExists 0 14 5
A langset.TestParseJsonIntoLang 0 6 3
A langset.TestGetFileContent 0 9 3
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
		}
46
	})
47
}
48