summaryrefslogtreecommitdiff
path: root/internal/findlinks/findlinks_test.go
blob: 79fb2413182973b7c4f623d4c94ceeab97b70357 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package findlinks

import (
	"os"
	"testing"

	"github.com/google/go-cmp/cmp"
)

func findLinksFile(filename string) ([]Link, error) {
	f, err := os.Open(filename)
	if err != nil {
		panic("can't open test file")
	}
	defer f.Close()

	return FindLinks(f)
}

func TestFindlinks(t *testing.T) {
	type test struct {
		filename string
		links    []Link
	}

	tests := []test{
		{
			"html/ex1.html",
			[]Link{
				{
					Href: "/other-page",
					Text: "A link to another page",
				},
			},
		},
	}

	for _, test := range tests {
		t.Run(test.filename, func(t *testing.T) {
			links, err := findLinksFile(test.filename)
			if err != nil {
				t.Error(err)
			}

			if !cmp.Equal(links, test.links) {
				t.Errorf("got %v, want %v", links, test.links)
			}
		})
	}

}