-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkOrchestrator_test.go
50 lines (43 loc) · 2.02 KB
/
workOrchestrator_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
package main
import (
"reflect"
"testing"
)
const startingUrl = "https://www.github.com"
const maxThreads = 100
const maxUrlsToCrawl = 10
func TestGetSiteMap_NoLinks(t *testing.T) {
mockResponse := map[string]string{"https://www.github.com": "adsf"}
actual := getSiteMap(&ClientMock{mockResponse}, maxThreads, startingUrl, maxUrlsToCrawl)
expected := map[string][]string{startingUrl: {}}
assertMapEquals(actual, expected, t)
}
func TestGetSiteMap_SingleLink(t *testing.T) {
mockResponse := map[string]string{"https://www.github.com": "<a href=\"https://www.github.com/notification\"><a href=\"https://www.xyz.com\">",
"https://www.github.com/notification": "Notification",
}
actual := getSiteMap(&ClientMock{mockResponse}, maxThreads, startingUrl, maxUrlsToCrawl)
expected := map[string][]string{startingUrl: {"https://www.github.com/notification"},
"https://www.github.com/notification": {},
}
assertMapEquals(actual, expected, t)
}
func TestGetSiteMap_SingleLink_ReferringItself(t *testing.T) {
mockResponse := map[string]string{"https://www.github.com": "<a href=\"https://www.github.com\"><a href=\"https://www.xyz.com\">"}
actual := getSiteMap(&ClientMock{mockResponse}, maxThreads, startingUrl, maxUrlsToCrawl)
expected := map[string][]string{startingUrl: {startingUrl}}
assertMapEquals(actual, expected, t)
}
func TestGetSiteMap_LimitMaxUrlsToCrawl(t *testing.T) {
mockResponse := map[string]string{"https://www.github.com": "<a href=\"https://www.github.com/notification\"><a href=\"https://www.xyz.com\">",
"https://www.github.com/notification": "<a href=\"https://www.github.com/status\">",
}
actual := getSiteMap(&ClientMock{mockResponse}, maxThreads, startingUrl, 2)
expected := map[string][]string{startingUrl: {"https://www.github.com/notification"}, "https://www.github.com/notification": {"https://www.github.com/status"}}
assertMapEquals(actual, expected, t)
}
func assertMapEquals(actual map[string][]string, expected map[string][]string, t *testing.T) {
if !reflect.DeepEqual(actual, expected) {
t.Error(actual)
}
}