storagenode/trust: fix go 1.14 failures

Change-Id: I6d147f8e5907666ffb3a3e487fa179e377c70841
This commit is contained in:
Egon Elbre 2020-03-24 12:57:14 +02:00
parent 326c0cebde
commit a9fb7b7694
4 changed files with 78 additions and 48 deletions

View File

@ -17,28 +17,32 @@ func TestNewExcluderFailure(t *testing.T) {
for _, tt := range []struct {
name string
config string
err string
errs []string
}{
{
name: "not a valid URL",
config: "://",
err: "exclusion: node URL error: parse ://: missing protocol scheme",
errs: []string{
`exclusion: node URL error: parse ://: missing protocol scheme`,
`exclusion: node URL error: parse "://": missing protocol scheme`,
},
},
{
name: "host exclusion must not include a port",
config: "bar.test:7777",
err: "exclusion: host exclusion must not include a port",
errs: []string{"exclusion: host exclusion must not include a port"},
},
{
name: "satellite URL exclusion must specify a port",
config: "121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@bar.test",
err: "exclusion: satellite URL exclusion must specify a port",
errs: []string{"exclusion: satellite URL exclusion must specify a port"},
},
} {
tt := tt // quiet linting
t.Run(tt.name, func(t *testing.T) {
_, err := trust.NewExcluder(tt.config)
require.EqualError(t, err, tt.err)
require.Error(t, err)
require.Contains(t, tt.errs, err.Error())
})
}

View File

@ -51,18 +51,21 @@ func TestFileSourceFetchEntries(t *testing.T) {
for _, tt := range []struct {
name string
path string
err string
errs []string
entries []trust.Entry
}{
{
name: "bad list",
path: badPath,
err: "file source: invalid satellite URL: must contain an ID",
errs: []string{"file source: invalid satellite URL: must contain an ID"},
},
{
name: "missing list",
path: missingPath,
err: fmt.Sprintf("file source: open %s: no such file or directory", missingPath),
errs: []string{
fmt.Sprintf("file source: open %s: no such file or directory", missingPath),
fmt.Sprintf("file source: open %s: The system cannot find the file specified.", missingPath),
},
},
{
name: "good list",
@ -83,8 +86,9 @@ func TestFileSourceFetchEntries(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
source := trust.NewFileSource(tt.path)
entries, err := source.FetchEntries(context.Background())
if tt.err != "" {
require.EqualError(t, err, tt.err)
if len(tt.errs) > 0 {
require.Error(t, err)
require.Contains(t, tt.errs, err.Error())
return
}
require.NoError(t, err)

View File

@ -20,27 +20,30 @@ func TestHTTPSourceNew(t *testing.T) {
for _, tt := range []struct {
name string
httpURL string
err string
errs []string
}{
{
name: "not a valid URL",
httpURL: "://",
err: `HTTP source: "://": not a URL: parse ://: missing protocol scheme`,
errs: []string{
`HTTP source: "://": not a URL: parse ://: missing protocol scheme`,
`HTTP source: "://": not a URL: parse "://": missing protocol scheme`,
},
},
{
name: "not an HTTP or HTTPS URL",
httpURL: "file://",
err: `HTTP source: "file://": scheme is not supported`,
errs: []string{`HTTP source: "file://": scheme is not supported`},
},
{
name: "missing host",
httpURL: "http:///path",
err: `HTTP source: "http:///path": host is missing`,
errs: []string{`HTTP source: "http:///path": host is missing`},
},
{
name: "fragment not allowed",
httpURL: "http://localhost/path#OHNO",
err: `HTTP source: "http://localhost/path#OHNO": fragment is not allowed`,
errs: []string{`HTTP source: "http://localhost/path#OHNO": fragment is not allowed`},
},
{
name: "success",
@ -50,8 +53,9 @@ func TestHTTPSourceNew(t *testing.T) {
tt := tt // quiet linting
t.Run(tt.name, func(t *testing.T) {
_, err := trust.NewHTTPSource(tt.httpURL)
if tt.err != "" {
require.EqualError(t, err, tt.err)
if len(tt.errs) > 0 {
require.Error(t, err)
require.Contains(t, tt.errs, err.Error())
return
}
require.NoError(t, err)

View File

@ -36,7 +36,7 @@ func TestSatelliteURLNodeURLConversion(t *testing.T) {
require.Equal(t, nodeURL, satelliteURL.NodeURL())
}
func TestParseSatelliteURL(t *testing.T) {
func TestParseSatelliteURL_Valid(t *testing.T) {
id, err := storj.NodeIDFromString("121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6")
require.NoError(t, err)
@ -44,33 +44,7 @@ func TestParseSatelliteURL(t *testing.T) {
name string
url string
parsed trust.SatelliteURL
err string
}{
{
name: "not a valid URL",
url: "://",
err: `invalid satellite URL: node URL error: parse ://: missing protocol scheme`,
},
{
name: "missing ID",
url: "127.0.0.1:7777",
err: "invalid satellite URL: must contain an ID",
},
{
name: "short ID",
url: "121RTSDpy@127.0.0.1:7777",
err: "invalid satellite URL: node URL error: node ID error: checksum error",
},
{
name: "missing host:port",
url: "121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@",
err: "invalid satellite URL: must specify the host:port",
},
{
name: "missing port",
url: "121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@127.0.0.1",
err: "invalid satellite URL: must specify the port",
},
{
name: "success",
url: "121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@127.0.0.1:7777",
@ -93,13 +67,57 @@ func TestParseSatelliteURL(t *testing.T) {
tt := tt // quiet linting
t.Run(tt.name, func(t *testing.T) {
u, err := trust.ParseSatelliteURL(tt.url)
if tt.err != "" {
require.EqualError(t, err, tt.err)
return
}
require.NoError(t, err)
require.Equal(t, tt.parsed, u)
})
}
}
func TestParseSatelliteURL_Invalid(t *testing.T) {
for _, tt := range []struct {
name string
url string
parsed trust.SatelliteURL
errs []string
}{
{
name: "not a valid URL",
url: "://",
errs: []string{
`invalid satellite URL: node URL error: parse ://: missing protocol scheme`,
`invalid satellite URL: node URL error: parse "://": missing protocol scheme`,
},
},
{
name: "missing ID",
url: "127.0.0.1:7777",
errs: []string{"invalid satellite URL: must contain an ID"},
},
{
name: "short ID",
url: "121RTSDpy@127.0.0.1:7777",
errs: []string{"invalid satellite URL: node URL error: node ID error: checksum error"},
},
{
name: "missing host:port",
url: "121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@",
errs: []string{
"invalid satellite URL: must specify the host:port",
"invalid satellite URL: must specify the host:port",
},
},
{
name: "missing port",
url: "121RTSDpyNZVcEU84Ticf2L1ntiuUimbWgfATz21tuvgk3vzoA6@127.0.0.1",
errs: []string{"invalid satellite URL: must specify the port"},
},
} {
tt := tt // quiet linting
t.Run(tt.name, func(t *testing.T) {
_, err := trust.ParseSatelliteURL(tt.url)
require.Error(t, err)
require.Contains(t, tt.errs, err.Error())
})
}
}