refactor: merge dnsx and errorsx into netxlite (#517)
When preparing a tutorial for netxlite, I figured it is easier to tell people "hey, this is the package you should use for all low-level networking stuff" rather than introducing people to a set of packages working together where some piece of functionality is here and some other piece is there. Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
parent
de130d249c
commit
6d3a4f1db8
169 changed files with 575 additions and 671 deletions
|
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/mockable"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -29,64 +29,64 @@ func TestTestKeysClassify(t *testing.T) {
|
|||
})
|
||||
t.Run("with tk.Target.Failure == connection_refused", func(t *testing.T) {
|
||||
tk := new(TestKeys)
|
||||
tk.Target.Failure = asStringPtr(errorsx.FailureConnectionRefused)
|
||||
tk.Target.Failure = asStringPtr(netxlite.FailureConnectionRefused)
|
||||
if tk.classify() != classAnomalyTestHelperUnreachable {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
})
|
||||
t.Run("with tk.Target.Failure == dns_nxdomain_error", func(t *testing.T) {
|
||||
tk := new(TestKeys)
|
||||
tk.Target.Failure = asStringPtr(errorsx.FailureDNSNXDOMAINError)
|
||||
tk.Target.Failure = asStringPtr(netxlite.FailureDNSNXDOMAINError)
|
||||
if tk.classify() != classAnomalyTestHelperUnreachable {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
})
|
||||
t.Run("with tk.Target.Failure == connection_reset", func(t *testing.T) {
|
||||
tk := new(TestKeys)
|
||||
tk.Target.Failure = asStringPtr(errorsx.FailureConnectionReset)
|
||||
tk.Target.Failure = asStringPtr(netxlite.FailureConnectionReset)
|
||||
if tk.classify() != classInterferenceReset {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
})
|
||||
t.Run("with tk.Target.Failure == eof_error", func(t *testing.T) {
|
||||
tk := new(TestKeys)
|
||||
tk.Target.Failure = asStringPtr(errorsx.FailureEOFError)
|
||||
tk.Target.Failure = asStringPtr(netxlite.FailureEOFError)
|
||||
if tk.classify() != classInterferenceClosed {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
})
|
||||
t.Run("with tk.Target.Failure == ssl_invalid_hostname", func(t *testing.T) {
|
||||
tk := new(TestKeys)
|
||||
tk.Target.Failure = asStringPtr(errorsx.FailureSSLInvalidHostname)
|
||||
tk.Target.Failure = asStringPtr(netxlite.FailureSSLInvalidHostname)
|
||||
if tk.classify() != classSuccessGotServerHello {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
})
|
||||
t.Run("with tk.Target.Failure == ssl_unknown_authority", func(t *testing.T) {
|
||||
tk := new(TestKeys)
|
||||
tk.Target.Failure = asStringPtr(errorsx.FailureSSLUnknownAuthority)
|
||||
tk.Target.Failure = asStringPtr(netxlite.FailureSSLUnknownAuthority)
|
||||
if tk.classify() != classInterferenceUnknownAuthority {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
})
|
||||
t.Run("with tk.Target.Failure == ssl_invalid_certificate", func(t *testing.T) {
|
||||
tk := new(TestKeys)
|
||||
tk.Target.Failure = asStringPtr(errorsx.FailureSSLInvalidCertificate)
|
||||
tk.Target.Failure = asStringPtr(netxlite.FailureSSLInvalidCertificate)
|
||||
if tk.classify() != classInterferenceInvalidCertificate {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
})
|
||||
t.Run("with tk.Target.Failure == generic_timeout_error #1", func(t *testing.T) {
|
||||
tk := new(TestKeys)
|
||||
tk.Target.Failure = asStringPtr(errorsx.FailureGenericTimeoutError)
|
||||
tk.Target.Failure = asStringPtr(netxlite.FailureGenericTimeoutError)
|
||||
if tk.classify() != classAnomalyTimeout {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
})
|
||||
t.Run("with tk.Target.Failure == generic_timeout_error #2", func(t *testing.T) {
|
||||
tk := new(TestKeys)
|
||||
tk.Target.Failure = asStringPtr(errorsx.FailureGenericTimeoutError)
|
||||
tk.Control.Failure = asStringPtr(errorsx.FailureGenericTimeoutError)
|
||||
tk.Target.Failure = asStringPtr(netxlite.FailureGenericTimeoutError)
|
||||
tk.Control.Failure = asStringPtr(netxlite.FailureGenericTimeoutError)
|
||||
if tk.classify() != classAnomalyTestHelperUnreachable {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
|
|
@ -191,10 +191,10 @@ func TestMeasureoneCancelledContext(t *testing.T) {
|
|||
if result.DNSCache != nil {
|
||||
t.Fatal("not the expected DNSCache")
|
||||
}
|
||||
if result.FailedOperation == nil || *result.FailedOperation != errorsx.TopLevelOperation {
|
||||
if result.FailedOperation == nil || *result.FailedOperation != netxlite.TopLevelOperation {
|
||||
t.Fatal("not the expected FailedOperation")
|
||||
}
|
||||
if result.Failure == nil || *result.Failure != errorsx.FailureInterrupted {
|
||||
if result.Failure == nil || *result.Failure != netxlite.FailureInterrupted {
|
||||
t.Fatal("not the expected failure")
|
||||
}
|
||||
if result.NetworkEvents != nil {
|
||||
|
|
@ -295,10 +295,10 @@ func TestMeasureoneSuccess(t *testing.T) {
|
|||
if result.DNSCache != nil {
|
||||
t.Fatal("not the expected DNSCache")
|
||||
}
|
||||
if result.FailedOperation == nil || *result.FailedOperation != errorsx.TLSHandshakeOperation {
|
||||
if result.FailedOperation == nil || *result.FailedOperation != netxlite.TLSHandshakeOperation {
|
||||
t.Fatal("not the expected FailedOperation")
|
||||
}
|
||||
if result.Failure == nil || *result.Failure != errorsx.FailureSSLInvalidHostname {
|
||||
if result.Failure == nil || *result.Failure != netxlite.FailureSSLInvalidHostname {
|
||||
t.Fatal("unexpected failure")
|
||||
}
|
||||
if len(result.NetworkEvents) < 1 {
|
||||
|
|
@ -348,7 +348,7 @@ func TestMeasureonewithcacheWorks(t *testing.T) {
|
|||
if result.Cached != expected {
|
||||
t.Fatal("unexpected cached")
|
||||
}
|
||||
if *result.Failure != errorsx.FailureSSLInvalidHostname {
|
||||
if *result.Failure != netxlite.FailureSSLInvalidHostname {
|
||||
t.Fatal("unexpected failure")
|
||||
}
|
||||
if result.SNI != "kernel.org" {
|
||||
|
|
|
|||
Loading…
Reference in a new issue