utils.TestGetAllInformation   A
last analyzed

Complexity

Conditions 5

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nop 1
dl 0
loc 20
rs 9.2833
c 0
b 0
f 0
1
package utils
2
3
import (
4
	"testing"
5
)
6
7
func TestGetPostsFromHTML(t *testing.T) {
8
	t.Run("returns links", func(t *testing.T) {
9
		fileText := FileGetContents("../storage/test_files/example")
10
		result := GetPostsFromHTML(&fileText)
11
12
		if len(result) != 8 {
13
			t.Error("GetLinksFromHTML must return slice with 8 items")
14
		}
15
	})
16
}
17
18
func TestGetAllInformation(t *testing.T) {
19
	t.Run("returns slice with PhotoReport models", func(t *testing.T) {
20
		links := []string{FileGetContents("../storage/test_files/item")}
21
22
		title := "Title here"
23
		img := "https://image.jpg"
24
		url := "https://test.com/hello/"
25
26
		result := GetAllInformation(&links)
27
28
		if result[0].Title != title {
29
			t.Error("Returned Title from GetAllInformation func must be `" + title + "` but `" + result[0].Title + "` returned")
30
		}
31
32
		if result[0].Image != img {
33
			t.Error("Returned Image from GetAllInformation func must be `" + img + "` but `" + result[0].Image + "` returned")
34
		}
35
36
		if result[0].URL != url {
37
			t.Error("Returned URL from GetAllInformation func must be `" + url + "` but `" + result[0].URL + "` returned")
38
		}
39
	})
40
}
41
42
func TestParseErrors(t *testing.T) {
43
	errorsContext := FileGetContents("../storage/test_files/error_log")
44
	result := ParseErrors(errorsContext)
45
46
	if len(result) != 2 {
47
		t.Errorf("Result must returns slice with 2 items but %v returned", len(result))
48
	}
49
}
50