Make error test portable

Fix URL error test portable on multiple Go versions.
This commit is contained in:
Atsushi Watanabe
2020-03-28 07:39:12 +09:00
parent 5ff1ae888f
commit d66df0461d

View File

@@ -2,6 +2,9 @@ package ice
import ( import (
"errors" "errors"
"fmt"
"net"
"net/url"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@@ -49,8 +52,8 @@ func TestParseURL(t *testing.T) {
expectedErr error expectedErr error
}{ }{
{"", ErrSchemeType}, {"", ErrSchemeType},
{":::", errors.New("parse :::: missing protocol scheme")}, {":::", errors.New("missing protocol scheme")},
{"stun:[::1]:123:", errors.New("address [::1]:123:: too many colons in address")}, {"stun:[::1]:123:", errors.New("too many colons in address")},
{"stun:[::1]:123a", ErrPort}, {"stun:[::1]:123a", ErrPort},
{"google.de", ErrSchemeType}, {"google.de", ErrSchemeType},
{"stun:", ErrHost}, {"stun:", ErrHost},
@@ -65,6 +68,12 @@ func TestParseURL(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
_, err := ParseURL(testCase.rawURL) _, err := ParseURL(testCase.rawURL)
switch e := err.(type) {
case *url.Error:
err = e.Err
case *net.AddrError:
err = fmt.Errorf("%v", e.Err)
}
assert.EqualError(t, err, testCase.expectedErr.Error(), "testCase: %d %v", i, testCase) assert.EqualError(t, err, testCase.expectedErr.Error(), "testCase: %d %v", i, testCase)
} }
}) })