From 0ae63793b3467f20966acdc58e3b34545ba547da Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Tue, 18 May 2021 06:59:13 +0200 Subject: [PATCH] Increase test coverage --- client_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/client_test.go b/client_test.go index 967bb3f6..44dc0c96 100644 --- a/client_test.go +++ b/client_test.go @@ -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} @@ -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) + } + }) + } +}