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:
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
|
||||
"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 (
|
||||
@@ -64,24 +64,24 @@ func (tk *TestKeys) classify() string {
|
||||
return classSuccessGotServerHello
|
||||
}
|
||||
switch *tk.Target.Failure {
|
||||
case errorsx.FailureConnectionRefused:
|
||||
case netxlite.FailureConnectionRefused:
|
||||
return classAnomalyTestHelperUnreachable
|
||||
case errorsx.FailureConnectionReset:
|
||||
case netxlite.FailureConnectionReset:
|
||||
return classInterferenceReset
|
||||
case errorsx.FailureDNSNXDOMAINError:
|
||||
case netxlite.FailureDNSNXDOMAINError:
|
||||
return classAnomalyTestHelperUnreachable
|
||||
case errorsx.FailureEOFError:
|
||||
case netxlite.FailureEOFError:
|
||||
return classInterferenceClosed
|
||||
case errorsx.FailureGenericTimeoutError:
|
||||
case netxlite.FailureGenericTimeoutError:
|
||||
if tk.Control.Failure != nil {
|
||||
return classAnomalyTestHelperUnreachable
|
||||
}
|
||||
return classAnomalyTimeout
|
||||
case errorsx.FailureSSLInvalidCertificate:
|
||||
case netxlite.FailureSSLInvalidCertificate:
|
||||
return classInterferenceInvalidCertificate
|
||||
case errorsx.FailureSSLInvalidHostname:
|
||||
case netxlite.FailureSSLInvalidHostname:
|
||||
return classSuccessGotServerHello
|
||||
case errorsx.FailureSSLUnknownAuthority:
|
||||
case netxlite.FailureSSLUnknownAuthority:
|
||||
return classInterferenceUnknownAuthority
|
||||
}
|
||||
return classAnomalyUnexpectedFailure
|
||||
@@ -117,8 +117,8 @@ func (m *Measurer) measureone(
|
||||
select {
|
||||
case <-time.After(sleeptime):
|
||||
case <-ctx.Done():
|
||||
s := errorsx.FailureInterrupted
|
||||
failedop := errorsx.TopLevelOperation
|
||||
s := netxlite.FailureInterrupted
|
||||
failedop := netxlite.TopLevelOperation
|
||||
return Subresult{
|
||||
TestKeys: urlgetter.TestKeys{
|
||||
FailedOperation: &failedop,
|
||||
|
||||
@@ -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" {
|
||||
|
||||
Reference in New Issue
Block a user