-
Notifications
You must be signed in to change notification settings - Fork 116
/
gnoi_cert_test.go
40 lines (36 loc) · 991 Bytes
/
gnoi_cert_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"crypto/tls"
"crypto/x509"
"testing"
"google.golang.org/grpc"
)
func TestGnoiEncrypted(t *testing.T) {
expectConn := &grpc.ClientConn{}
dial = func(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
return expectConn, nil
}
conn, client := gnoiEncrypted(tls.Certificate{})
if expectConn != conn {
t.Errorf("Invalid connection (-want +got): -%v, +%v", expectConn, conn)
}
if client == nil {
t.Error("Expected non-nil client")
}
}
func TestGnoiAuthenticated(t *testing.T) {
expectConn := &grpc.ClientConn{}
dial = func(target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
return expectConn, nil
}
loadCerts = func() ([]tls.Certificate, *x509.CertPool) {
return []tls.Certificate{}, &x509.CertPool{}
}
conn, client := gnoiAuthenticated("test")
if expectConn != conn {
t.Errorf("Invalid connection (-want +got): -%v, +%v", expectConn, conn)
}
if client == nil {
t.Error("Expected non-nil client")
}
}