-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape_test.go
106 lines (99 loc) · 3.36 KB
/
scrape_test.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package rotten_tomato
import (
"log"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/assert"
)
var MATRIX_YEAR = 1999
func testScrapeActors(t *testing.T, proxyUrl string) {
expected := []RTSchemaPerson{
{
Name: "Keanu Reeves",
Url: "https://www.rottentomatoes.com/celebrity/keanu_reeves",
Image: "https://resizing.flixster.com/YARxkSH8c59kDC2pA87rGSQ8uX0=/100x120/v2/https://flxt.tmsimg.com/assets/1443_v9_bc.jpg",
},
{
Name: "Laurence Fishburne",
Url: "https://www.rottentomatoes.com/celebrity/larry_fishburne",
Image: "https://resizing.flixster.com/K9EdHynqolK6JE8ZB_9-fNb0KhA=/100x120/v2/https://flxt.tmsimg.com/assets/71229_v9_bb.jpg",
},
{
Name: "Carrie-Anne Moss",
Url: "https://www.rottentomatoes.com/celebrity/carrie_anne_moss",
Image: "https://resizing.flixster.com/o1J5kMouS0pTlmH7Zp4NEpBuJD0=/100x120/v2/https://flxt.tmsimg.com/assets/78172_v9_bb.jpg",
},
{
Name: "Hugo Weaving",
Url: "https://www.rottentomatoes.com/celebrity/hugo_weaving",
Image: "https://resizing.flixster.com/l4YJKIcNoGzuyVJXq_egJIc25Lw=/100x120/v2/https://flxt.tmsimg.com/assets/27163_v9_bb.jpg",
},
{
Name: "Joe Pantoliano",
Url: "https://www.rottentomatoes.com/celebrity/joe_pantoliano",
Image: "https://resizing.flixster.com/G0MMX7KZ0DZG0rxtg6UwxdK-sMM=/100x120/v2/https://flxt.tmsimg.com/assets/32287_v9_bb.jpg",
},
}
actors, err := GetActors("the matrix", &MATRIX_YEAR, 5, proxyUrl)
if err != nil {
t.Fatalf("error occurred while scraping `the matrix` actors: %+v", err)
}
assert.Equal(t, actors, expected)
}
func testScrapeDirectors(t *testing.T, proxyUrl string) {
expected := []RTSchemaPerson{
{
Name: "Lilly Wachowski",
Url: "https://www.rottentomatoes.com/celebrity/lilly_wachowski",
Image: "https://resizing.flixster.com/tj_RivcrCUlgfuV8xJb6koyPRYo=/100x120/v2/https://flxt.tmsimg.com/assets/150670_v9_ba.jpg",
},
{
Name: "Lana Wachowski",
Url: "https://www.rottentomatoes.com/celebrity/lana_wachowski",
Image: "https://resizing.flixster.com/nIZRovwZGWwrmpbqjmsUrFa9HgI=/100x120/v2/https://flxt.tmsimg.com/assets/150673_v9_ba.jpg",
},
}
directors, err := GetDirectors("the matrix", &MATRIX_YEAR, 0, proxyUrl)
if err != nil {
t.Fatalf("error occurred while scraping `the matrix` directors: %+v", err)
}
assert.Equal(t, directors, expected)
}
func TestScrapeMovieInfo(t *testing.T) {
expectedMoveInfos := []RTMovieInfo{
{
Title: "The Matrix",
Year: 1999,
Rating: "R",
Runtime: "2h 16m",
Genres: []string{"Sci-fi", "Action"},
AudienceScore: RTScore{
AverageRating: "3.6",
BandedRatingCount: "250,000+",
LikedCount: 142778,
NotLikedCount: 24632,
RatingCount: 33324202,
ReviewCount: 1307885,
State: "upright",
Value: 85,
},
TomatometerScore: RTScore{
AverageRating: "7.70",
BandedRatingCount: "",
LikedCount: 171,
NotLikedCount: 36,
RatingCount: 207,
ReviewCount: 207,
State: "certified-fresh",
Value: 83,
},
},
}
for _, expectedMoveInfo := range expectedMoveInfos {
movieInfo, err := GetMovieInfo(expectedMoveInfo.Title, &expectedMoveInfo.Year, "")
if err != nil {
log.Fatalf("Error: %v", err.Error())
}
assert.Equal(t, cmp.Equal(*movieInfo, expectedMoveInfo), true)
}
}