2021-05-21 12:16:07 +00:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAddress_TLSEnabled(t *testing.T) {
|
|
|
|
testCases := [...]struct {
|
|
|
|
input string
|
|
|
|
wantTLS bool
|
|
|
|
}{
|
|
|
|
{"/dns4/localhost/tcp/8080", false},
|
|
|
|
{"/dns4/localhost/tcp/8080/tls", true},
|
|
|
|
{"/tls/dns4/localhost/tcp/8080", true},
|
2021-06-24 12:25:11 +00:00
|
|
|
{"grpc://localhost:8080", false},
|
|
|
|
{"grpcs://localhost:8080", true},
|
2021-05-21 12:16:07 +00:00
|
|
|
}
|
|
|
|
|
2021-06-24 12:25:11 +00:00
|
|
|
var addr Address
|
|
|
|
|
2021-05-21 12:16:07 +00:00
|
|
|
for _, test := range testCases {
|
2021-06-24 12:25:11 +00:00
|
|
|
err := addr.FromString(test.input)
|
|
|
|
require.NoError(t, err)
|
2021-05-21 12:16:07 +00:00
|
|
|
|
2023-06-26 12:00:44 +00:00
|
|
|
require.Equal(t, test.wantTLS, addr.IsTLSEnabled(), test.input)
|
2021-05-21 12:16:07 +00:00
|
|
|
}
|
|
|
|
}
|