refactor(netx): move tlshandshaker logger to netxlite (#402)
Part of https://github.com/ooni/probe/issues/1505
This commit is contained in:
parent
acef18a955
commit
f1ee763f94
11 changed files with 151 additions and 79 deletions
33
internal/netxmocks/tlshandshaker_test.go
Normal file
33
internal/netxmocks/tlshandshaker_test.go
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package netxmocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"net"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTLSHandshakerHandshake(t *testing.T) {
|
||||
expected := errors.New("mocked error")
|
||||
conn := &Conn{}
|
||||
ctx := context.Background()
|
||||
config := &tls.Config{}
|
||||
th := &TLSHandshaker{
|
||||
MockHandshake: func(ctx context.Context, conn net.Conn,
|
||||
config *tls.Config) (net.Conn, tls.ConnectionState, error) {
|
||||
return nil, tls.ConnectionState{}, expected
|
||||
},
|
||||
}
|
||||
tlsConn, connState, err := th.Handshake(ctx, conn, config)
|
||||
if !errors.Is(err, expected) {
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
if !reflect.ValueOf(connState).IsZero() {
|
||||
t.Fatal("expected zero ConnectionState here")
|
||||
}
|
||||
if tlsConn != nil {
|
||||
t.Fatal("expected nil conn here")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue