~chrisppy/go-barefeed

ref: 022d6ea6f0215c28fa4b4b69dd9d821c8766ded8 go-barefeed/link_test.go -rw-r--r-- 1.4 KiB
022d6ea6Chris Palmer updates from barefeed fixes 5 months ago
                                                                                
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
52
53
package barefeed

import "testing"

func testLinks(t *testing.T, expected, actual Links) {
	if len(expected) != len(actual) {
		t.Errorf("Expected %d links, actual %d links", len(expected), len(actual))
	}
	for j := 0; j < len(expected); j++ {
		if expected[j].URL != actual[j].URL {
			t.Errorf("Expected %s, actual %s", expected[j].URL, actual[j].URL)
		}
		if expected[j].Type != actual[j].Type {
			t.Errorf("Expected %s, actual %s", expected[j].Type, actual[j].Type)
		}
		if expected[j].Rel != actual[j].Rel {
			t.Errorf("Expected %s, actual %s", expected[j].Rel, actual[j].Rel)
		}
		if expected[j].Length != actual[j].Length {
			t.Errorf("Expected %d, actual %d", expected[j].Length, actual[j].Length)
		}
		if actual[j].Position != expected[j].Position {
			if expected[j].Position == nil {
				t.Errorf("Expected nil, actual %d", *actual[j].Position)
			} else if actual[j].Position == nil {
				t.Errorf("Expected %d, actual nil", *expected[j].Position)
			} else if *actual[j].Position != *expected[j].Position {
				t.Errorf("Expected %d, actual %d", *expected[j].Position, *actual[j].Position)
			}
		}
	}
}

func getLinks() Links {
	pos := 1000000
	a := Link{
		URL:      "https://example.com/entry.mp3",
		Type:     "audio/mp3",
		Rel:      "enclosure",
		Length:   50416767,
		Position: &pos,
	}

	b := Link{
		URL:      "https://example.com/feed.xml",
		Type:     "plain/html",
		Rel:      "self",
		Length:   123,
		Position: nil,
	}

	return Links{a, b}
}