feat(ooniprobe): discard lists not in selected categories (#278)
* feat(ooniprobe): discard lists not in selected categories One day we may make an integration mistake and for any reason we may end up with URLs that do not belong to the categories originally selected by the user. If that happens, it's nice to have a safety net where we remove URLs that do not belong to the right category before proceeding with testing. This diff was conceived while discussing the robustness of https://github.com/ooni/probe/issues/1299 with @hellais. * fix behavior and add unit test * more robust
This commit is contained in:
parent
969d8b772f
commit
5c47a87af7
2 changed files with 104 additions and 2 deletions
77
cmd/ooniprobe/internal/nettests/web_connectivity_test.go
Normal file
77
cmd/ooniprobe/internal/nettests/web_connectivity_test.go
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
package nettests
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
||||
)
|
||||
|
||||
func TestPreventMistakesWithCategories(t *testing.T) {
|
||||
input := []model.URLInfo{{
|
||||
CategoryCode: "NEWS",
|
||||
URL: "https://repubblica.it/",
|
||||
CountryCode: "IT",
|
||||
}, {
|
||||
CategoryCode: "HACK",
|
||||
URL: "https://2600.com",
|
||||
CountryCode: "XX",
|
||||
}, {
|
||||
CategoryCode: "FILE",
|
||||
URL: "https://addons.mozilla.org/",
|
||||
CountryCode: "XX",
|
||||
}}
|
||||
desired := []model.URLInfo{{
|
||||
CategoryCode: "NEWS",
|
||||
URL: "https://repubblica.it/",
|
||||
CountryCode: "IT",
|
||||
}, {
|
||||
CategoryCode: "FILE",
|
||||
URL: "https://addons.mozilla.org/",
|
||||
CountryCode: "XX",
|
||||
}}
|
||||
output := preventMistakes(input, []string{"NEWS", "FILE"})
|
||||
if diff := cmp.Diff(desired, output); diff != "" {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreventMistakesWithoutCategoriesAndNil(t *testing.T) {
|
||||
input := []model.URLInfo{{
|
||||
CategoryCode: "NEWS",
|
||||
URL: "https://repubblica.it/",
|
||||
CountryCode: "IT",
|
||||
}, {
|
||||
CategoryCode: "HACK",
|
||||
URL: "https://2600.com",
|
||||
CountryCode: "XX",
|
||||
}, {
|
||||
CategoryCode: "FILE",
|
||||
URL: "https://addons.mozilla.org/",
|
||||
CountryCode: "XX",
|
||||
}}
|
||||
output := preventMistakes(input, nil)
|
||||
if diff := cmp.Diff(input, output); diff != "" {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreventMistakesWithoutCategoriesAndEmpty(t *testing.T) {
|
||||
input := []model.URLInfo{{
|
||||
CategoryCode: "NEWS",
|
||||
URL: "https://repubblica.it/",
|
||||
CountryCode: "IT",
|
||||
}, {
|
||||
CategoryCode: "HACK",
|
||||
URL: "https://2600.com",
|
||||
CountryCode: "XX",
|
||||
}, {
|
||||
CategoryCode: "FILE",
|
||||
URL: "https://addons.mozilla.org/",
|
||||
CountryCode: "XX",
|
||||
}}
|
||||
output := preventMistakes(input, []string{})
|
||||
if diff := cmp.Diff(input, output); diff != "" {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue