Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed May 18, 2021
1 parent 6f5c9e4 commit 0ae6379
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context"
)

var testClient = Client{Debug: true}
Expand Down Expand Up @@ -144,3 +145,29 @@ func TestGetPlaylist(t *testing.T) {
assert.Equal(173*time.Second, playlist.Videos[0].Duration)
}
}

func TestClient_httpGetBodyBytes(t *testing.T) {
tests := []struct {
url string
errorContains string
}{
{"unknown://", "unsupported protocol scheme"},
{"invalid\nurl", "invalid control character in URL"},
{"http://unknown-host/", "dial tcp"},
{"http://example.com/does-not-exist", "unexpected status code: 404"},
{"http://example.com/", ""},
}
for _, tt := range tests {
t.Run(tt.url, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, err := testClient.httpGetBodyBytes(ctx, tt.url)

if tt.errorContains == "" {
assert.NoError(t, err)
} else if assert.Error(t, err) {
assert.Contains(t, err.Error(), tt.errorContains)
}
})
}
}

0 comments on commit 0ae6379

Please sign in to comment.