Use _test package to force use of public API
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
package goutubedl
|
||||
package goutubedl_test
|
||||
|
||||
// TODO: currently the tests only run on linux as they use osleaktest which only
|
||||
// has linux support
|
||||
@ -14,9 +14,15 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/fortytw2/leaktest"
|
||||
"github.com/wader/goutubedl"
|
||||
"github.com/wader/osleaktest"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// we're using yt-dlp at the moment
|
||||
goutubedl.Path = "yt-dlp"
|
||||
}
|
||||
|
||||
const testVideoRawURL = "https://www.youtube.com/watch?v=C0DPdy98e4c"
|
||||
const playlistRawURL = "https://soundcloud.com/mattheis/sets/kindred-phenomena"
|
||||
const subtitlesTestVideoRawURL = "https://www.youtube.com/watch?v=QRS8MkLhQmM"
|
||||
@ -33,10 +39,10 @@ func leakChecks(t *testing.T) func() {
|
||||
|
||||
func TestBinaryNotPath(t *testing.T) {
|
||||
defer leakChecks(t)()
|
||||
defer func(orig string) { Path = orig }(Path)
|
||||
Path = "/non-existing"
|
||||
defer func(orig string) { goutubedl.Path = orig }(goutubedl.Path)
|
||||
goutubedl.Path = "/non-existing"
|
||||
|
||||
_, versionErr := Version(context.Background())
|
||||
_, versionErr := goutubedl.Version(context.Background())
|
||||
if versionErr == nil || !strings.Contains(versionErr.Error(), "no such file or directory") {
|
||||
t.Fatalf("err should be nil 'no such file or directory': %v", versionErr)
|
||||
}
|
||||
@ -46,7 +52,7 @@ func TestVersion(t *testing.T) {
|
||||
defer leakChecks(t)()
|
||||
|
||||
versionRe := regexp.MustCompile(`^\d{4}\.\d{2}.\d{2}.*$`)
|
||||
version, versionErr := Version(context.Background())
|
||||
version, versionErr := goutubedl.Version(context.Background())
|
||||
|
||||
if versionErr != nil {
|
||||
t.Fatalf("err: %s", versionErr)
|
||||
@ -61,7 +67,7 @@ func TestDownload(t *testing.T) {
|
||||
defer leakChecks(t)()
|
||||
|
||||
stderrBuf := &bytes.Buffer{}
|
||||
r, err := New(context.Background(), testVideoRawURL, Options{
|
||||
r, err := goutubedl.New(context.Background(), testVideoRawURL, goutubedl.Options{
|
||||
StderrFn: func(cmd *exec.Cmd) io.Writer {
|
||||
return stderrBuf
|
||||
},
|
||||
@ -84,8 +90,8 @@ func TestDownload(t *testing.T) {
|
||||
t.Errorf("copy n not equal to download buffer: %d!=%d", n, downloadBuf.Len())
|
||||
}
|
||||
|
||||
if n < 29000 {
|
||||
t.Errorf("should have copied at least 29000 bytes: %d", n)
|
||||
if n < 10000 {
|
||||
t.Errorf("should have copied at least 10000 bytes: %d", n)
|
||||
}
|
||||
|
||||
if !strings.Contains(stderrBuf.String(), "Destination") {
|
||||
@ -106,7 +112,7 @@ func TestParseInfo(t *testing.T) {
|
||||
defer leakChecks(t)()
|
||||
|
||||
ctx, cancelFn := context.WithCancel(context.Background())
|
||||
ydlResult, err := New(ctx, c.url, Options{
|
||||
ydlResult, err := goutubedl.New(ctx, c.url, goutubedl.Options{
|
||||
DownloadThumbnail: true,
|
||||
})
|
||||
if err != nil {
|
||||
@ -156,8 +162,8 @@ func TestParseInfo(t *testing.T) {
|
||||
func TestPlaylist(t *testing.T) {
|
||||
defer leakChecks(t)()
|
||||
|
||||
ydlResult, ydlResultErr := New(context.Background(), playlistRawURL, Options{
|
||||
Type: TypePlaylist,
|
||||
ydlResult, ydlResultErr := goutubedl.New(context.Background(), playlistRawURL, goutubedl.Options{
|
||||
Type: goutubedl.TypePlaylist,
|
||||
DownloadThumbnail: false,
|
||||
})
|
||||
|
||||
@ -184,7 +190,7 @@ func TestPlaylist(t *testing.T) {
|
||||
func TestTestUnsupportedURL(t *testing.T) {
|
||||
defer leaktest.Check(t)()
|
||||
|
||||
_, ydlResultErr := New(context.Background(), "https://www.google.com", Options{})
|
||||
_, ydlResultErr := goutubedl.New(context.Background(), "https://www.google.com", goutubedl.Options{})
|
||||
if ydlResultErr == nil {
|
||||
t.Errorf("expected unsupported url")
|
||||
}
|
||||
@ -199,8 +205,8 @@ func TestPlaylistWithPrivateVideo(t *testing.T) {
|
||||
defer leaktest.Check(t)()
|
||||
|
||||
playlistRawURL := "https://www.youtube.com/playlist?list=PLX0g748fkegS54oiDN4AXKl7BR7mLIydP"
|
||||
ydlResult, ydlResultErr := New(context.Background(), playlistRawURL, Options{
|
||||
Type: TypePlaylist,
|
||||
ydlResult, ydlResultErr := goutubedl.New(context.Background(), playlistRawURL, goutubedl.Options{
|
||||
Type: goutubedl.TypePlaylist,
|
||||
DownloadThumbnail: false,
|
||||
})
|
||||
|
||||
@ -218,10 +224,10 @@ func TestPlaylistWithPrivateVideo(t *testing.T) {
|
||||
func TestSubtitles(t *testing.T) {
|
||||
defer leakChecks(t)()
|
||||
|
||||
ydlResult, ydlResultErr := New(
|
||||
ydlResult, ydlResultErr := goutubedl.New(
|
||||
context.Background(),
|
||||
subtitlesTestVideoRawURL,
|
||||
Options{
|
||||
goutubedl.Options{
|
||||
DownloadSubtitles: true,
|
||||
})
|
||||
|
||||
@ -250,11 +256,11 @@ func TestSubtitles(t *testing.T) {
|
||||
func TestErrorNotAPlaylist(t *testing.T) {
|
||||
defer leakChecks(t)()
|
||||
|
||||
_, ydlResultErr := New(context.Background(), testVideoRawURL, Options{
|
||||
Type: TypePlaylist,
|
||||
_, ydlResultErr := goutubedl.New(context.Background(), testVideoRawURL, goutubedl.Options{
|
||||
Type: goutubedl.TypePlaylist,
|
||||
DownloadThumbnail: false,
|
||||
})
|
||||
if ydlResultErr != ErrNotAPlaylist {
|
||||
if ydlResultErr != goutubedl.ErrNotAPlaylist {
|
||||
t.Errorf("expected is playlist error, got %s", ydlResultErr)
|
||||
}
|
||||
}
|
||||
@ -262,11 +268,11 @@ func TestErrorNotAPlaylist(t *testing.T) {
|
||||
func TestErrorNotASingleEntry(t *testing.T) {
|
||||
defer leakChecks(t)()
|
||||
|
||||
_, ydlResultErr := New(context.Background(), playlistRawURL, Options{
|
||||
Type: TypeSingle,
|
||||
_, ydlResultErr := goutubedl.New(context.Background(), playlistRawURL, goutubedl.Options{
|
||||
Type: goutubedl.TypeSingle,
|
||||
DownloadThumbnail: false,
|
||||
})
|
||||
if ydlResultErr != ErrNotASingleEntry {
|
||||
if ydlResultErr != goutubedl.ErrNotASingleEntry {
|
||||
t.Errorf("expected is single entry error, got %s", ydlResultErr)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user