refactor(simplequicping): use step-by-step (#852)
See https://github.com/ooni/probe/issues/2159 and https://github.com/ooni/spec/pull/254
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
@@ -25,6 +26,11 @@ type Trace struct {
|
||||
|
||||
MockOnTLSHandshakeDone func(started time.Time, remoteAddr string, config *tls.Config,
|
||||
state tls.ConnectionState, err error, finished time.Time)
|
||||
|
||||
MockOnQUICHandshakeStart func(now time.Time, remoteAddrs string, config *quic.Config)
|
||||
|
||||
MockOnQUICHandshakeDone func(started time.Time, remoteAddr string, qconn quic.EarlyConnection,
|
||||
config *tls.Config, err error, finished time.Time)
|
||||
}
|
||||
|
||||
var _ model.Trace = &Trace{}
|
||||
@@ -51,3 +57,12 @@ func (t *Trace) OnTLSHandshakeDone(started time.Time, remoteAddr string, config
|
||||
state tls.ConnectionState, err error, finished time.Time) {
|
||||
t.MockOnTLSHandshakeDone(started, remoteAddr, config, state, err, finished)
|
||||
}
|
||||
|
||||
func (t *Trace) OnQUICHandshakeStart(now time.Time, remoteAddr string, config *quic.Config) {
|
||||
t.MockOnQUICHandshakeStart(now, remoteAddr, config)
|
||||
}
|
||||
|
||||
func (t *Trace) OnQUICHandshakeDone(started time.Time, remoteAddr string, qconn quic.EarlyConnection,
|
||||
config *tls.Config, err error, finished time.Time) {
|
||||
t.MockOnQUICHandshakeDone(started, remoteAddr, qconn, config, err, finished)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
@@ -95,4 +96,37 @@ func TestTrace(t *testing.T) {
|
||||
t.Fatal("not called")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("OnQUICHandshakeStart", func(t *testing.T) {
|
||||
var called bool
|
||||
tx := &Trace{
|
||||
MockOnQUICHandshakeStart: func(now time.Time, remoteAddrs string, config *quic.Config) {
|
||||
called = true
|
||||
},
|
||||
}
|
||||
tx.OnQUICHandshakeStart(time.Now(), "1.1.1.1:443", &quic.Config{})
|
||||
if !called {
|
||||
t.Fatal("not called")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("OnQUICHandshakeDone", func(t *testing.T) {
|
||||
var called bool
|
||||
tx := &Trace{
|
||||
MockOnQUICHandshakeDone: func(started time.Time, remoteAddr string, qconn quic.EarlyConnection, config *tls.Config, err error, finished time.Time) {
|
||||
called = true
|
||||
},
|
||||
}
|
||||
tx.OnQUICHandshakeDone(
|
||||
time.Now(),
|
||||
"1.1.1.1:443",
|
||||
nil,
|
||||
&tls.Config{},
|
||||
nil,
|
||||
time.Now(),
|
||||
)
|
||||
if !called {
|
||||
t.Fatal("not called")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user