Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 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 | } |
||
50 |