Skip to content

Commit

Permalink
More robust http error check in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anbsky committed Mar 24, 2021
1 parent ee1e435 commit d909efb
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions app/publish/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"mime/multipart"
"net/http"
"net/http/httptest"
"net/url"
"os"
"path"
"testing"
Expand Down Expand Up @@ -201,20 +200,17 @@ func Test_fetchFileInvalidInput(t *testing.T) {
{"http://ovh.net/files/nonexistant1Mb.dat", "remote server returned non-OK status 404"},
{"/etc/passwd", `Get "/etc/passwd": unsupported protocol scheme ""`},
{"https://odysee.tv/../../../etc/passwd", "remote server returned non-OK status 400"},
{"http://nonexistenthost/some_file.mp4", `Get "http://nonexistenthost/some_file.mp4": dial tcp: lookup nonexistenthost: no such host`},
{"http://nonexistenthost/some_file.mp4", `dial tcp: lookup nonexistenthost:`},
{"http://nonexistenthost/", "couldn't determine remote file name"},
{"/", "couldn't determine remote file name"},
}

for _, c := range cases {
t.Run(c.url, func(t *testing.T) {
data := url.Values{}
data.Add(remoteURLParam, "http://odysee.tv/just/some_file.mp4")

r := CreatePublishRequest(t, nil, FormParam{remoteURLParam, c.url})

_, err := h.fetchFile(r, 20404)
require.EqualError(t, err, c.errMsg)
assert.Regexp(t, fmt.Sprintf(".*%v.*", c.errMsg), err.Error())
})
}
}
Expand Down

0 comments on commit d909efb

Please sign in to comment.