2021-02-02 12:05:47 +01:00
|
|
|
package probeservices_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFetchURLListSuccess(t *testing.T) {
|
2021-09-05 11:58:02 +02:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skip test in short mode")
|
|
|
|
}
|
2021-02-02 12:05:47 +01:00
|
|
|
client := newclient()
|
|
|
|
client.BaseURL = "https://ams-pg-test.ooni.org"
|
|
|
|
config := model.URLListConfig{
|
|
|
|
Categories: []string{"NEWS", "CULTR"},
|
|
|
|
CountryCode: "IT",
|
|
|
|
Limit: 17,
|
|
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
result, err := client.FetchURLList(ctx, config)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(result) != 17 {
|
|
|
|
t.Fatal("unexpected number of results")
|
|
|
|
}
|
|
|
|
for _, entry := range result {
|
|
|
|
if entry.CategoryCode != "NEWS" && entry.CategoryCode != "CULTR" {
|
|
|
|
t.Fatalf("unexpected category code: %+v", entry)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFetchURLListFailure(t *testing.T) {
|
|
|
|
client := newclient()
|
|
|
|
client.BaseURL = "https://\t\t\t/" // cause test to fail
|
|
|
|
config := model.URLListConfig{
|
|
|
|
Categories: []string{"NEWS", "CULTR"},
|
|
|
|
CountryCode: "IT",
|
|
|
|
Limit: 17,
|
|
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
result, err := client.FetchURLList(ctx, config)
|
|
|
|
if err == nil || !strings.HasSuffix(err.Error(), "invalid control character in URL") {
|
|
|
|
t.Fatal("not the error we expected")
|
|
|
|
}
|
|
|
|
if len(result) != 0 {
|
|
|
|
t.Fatal("results?!")
|
|
|
|
}
|
|
|
|
}
|