aboutsummaryrefslogtreecommitdiff
path: root/manager_test.go
blob: d0d2e35374ecfa99f4c1c81b47005ad3201410b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main

import (
	"errors"
	"fmt"
	"math/rand"
	"os"
	"strings"
	"testing"

	"git.sr.ht/~gabrielgio/midr/yt"
	"github.com/stretchr/testify/assert"
)

const charset = "0123456789abcdef"

func randomString(length int) string {
	sb := strings.Builder{}
	sb.Grow(length)
	for i := 0; i < length; i++ {
		sb.WriteByte(charset[rand.Intn(len(charset))])
	}
	return sb.String()
}

func exists(path string) bool {
	_, err := os.Stat(path)
	return !errors.Is(err, os.ErrNotExist)
}

func TestDownloadProcess(t *testing.T) {
	random := randomString(5)
	tmp := fmt.Sprintf("/tmp/%s", random)
	link := "https://www.youtube.com/watch?v=zGDzdps75ns"
	yt.RunYtDlpProcess(link, tmp)

	full_tmp_path := fmt.Sprintf("%s/Small short test video.webm", tmp)
	assert.True(t, exists(full_tmp_path), "it worked?")

	e := os.Remove(full_tmp_path)
	if e != nil {
		assert.FailNow(t, "File not removed properly")
	}

}