Skip to content

Commit

Permalink
add few more tests with custom http client
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalone committed Jul 13, 2024
1 parent ce656fa commit 224c668
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions ytsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,42 @@ package ytsearch

import (
"context"
"net/http"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func Test_Search(t *testing.T) {
c := Client{}
res, err := c.Search("nocopyrightsounds")
t.Run("with default http client", func(t *testing.T) {
c := Client{}
res, err := c.Search("nocopyrightsounds")

// no errors
assert.NoError(t, err)

// response is not empty
assert.NotEmpty(t, res.Results, "results are empty")

// no errors
assert.NoError(t, err)
// continuation key is not empty
assert.NotEmpty(t, res.Continuation, "continuation token is empty")
})

t.Run("with custom http client", func(t *testing.T) {
httpclient := &http.Client{
Timeout: time.Nanosecond * 1,
}

// response is not empty
assert.NotEmpty(t, res.Results, "results are empty")
// client
c := Client{
HTTPClient: httpclient,
}
res, err := c.Search("nocopyrightsounds")

// continuation key is not empty
assert.NotEmpty(t, res.Continuation, "continuation token is empty")
assert.ErrorContains(t, err, context.DeadlineExceeded.Error())
assert.Empty(t, res)
})
}

func Test_SearchWithContext(t *testing.T) {
Expand Down

0 comments on commit 224c668

Please sign in to comment.