You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gohperhole/blocklists_test.go

101 lines
3.6 KiB

package main
import (
"context"
"reflect"
"testing"
)
func TestFetchBlockList(t *testing.T) {
type args struct {
source string
}
tests := []struct {
name string
source string
want Blocklist
wantErr bool
}{
{
name: "test complex block list",
source: "https://gist.githubusercontent.com/adamveld12/7d7a236344c48d6e00cc4bd0d88079bf/raw/93b837ff443d1e4c4c9a381275733fd28d16b5f7/blacklist.txt",
want: Blocklist{
Source: "https://gist.githubusercontent.com/adamveld12/7d7a236344c48d6e00cc4bd0d88079bf/raw/93b837ff443d1e4c4c9a381275733fd28d16b5f7/blacklist.txt",
Domains: map[string]string{
"local": "",
"ip6-localnet": "",
"ip6-mcastprefix": "",
"ip6-allnodes": "",
"ip6-allrouters": "",
"ip6-allhosts": "",
"01mspmd5yalky8.com": "",
"0byv9mgbn0.com": "",
"analytics.247sports.com": "",
"www.analytics.247sports.com": "",
"2no.co": "",
"www.2no.co": "",
"logitechlogitechglobal.112.2o7.net": "",
"www.logitechlogitechglobal.112.2o7.net": "",
"30-day-change.com": "",
"www.30-day-change.com": "",
},
},
},
{
name: "test simple block list",
source: "https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt",
want: Blocklist{
Source: "https://s3.amazonaws.com/lists.disconnect.me/simple_tracking.txt",
Domains: map[string]string{
"adjust.io": "",
"airbrake.io": "",
"appboy.com": "",
"appsflyer.com": "",
"apsalar.com": "",
"bango.combango.org": "",
"bango.net": "",
"basic-check.disconnect.me": "",
"bkrtx.com": "",
"bluekai.com": "",
"bugsense.com": "",
"burstly.com": "",
"chartboost.com": "",
"count.ly": "",
"crashlytics.com": "",
"crittercism.com": "",
"custom-blacklisted-tracking-example.com": "",
"do-not-tracker.org": "",
"eviltracker.net": "",
"flurry.com": "",
"getexceptional.com": "",
"inmobi.com": "",
"jumptap.com": "",
"localytics.com": "",
"mixpanel.com": "",
"mobile-collector.newrelic.com": "",
"mobileapptracking.com": "",
"playtomic.com": "",
"stathat.com": "",
"supercell.net": "",
"tapjoy.com": "",
"trackersimulator.org": "",
"usergrid.com": "",
"vungle.com": "",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := CreateBlockList(context.Background(), tt.source)
if (err != nil) != tt.wantErr {
t.Errorf("FetchBlockList() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("FetchBlockList() = %+v, want %+v", got, tt.want)
}
})
}
}