midr @ 40d80bde511a7a76a0f5a3c16afc9eef2e5972e2

 1package main
 2
 3import (
 4	"errors"
 5	"fmt"
 6	"math/rand"
 7	"os"
 8	"strings"
 9	"testing"
10
11	"git.sr.ht/~gabrielgio/midr/yt"
12	"github.com/stretchr/testify/assert"
13)
14
15const charset = "0123456789abcdef"
16
17func randomString(length int) string {
18	sb := strings.Builder{}
19	sb.Grow(length)
20	for i := 0; i < length; i++ {
21		sb.WriteByte(charset[rand.Intn(len(charset))])
22	}
23	return sb.String()
24}
25
26func exists(path string) bool {
27	_, err := os.Stat(path)
28	return !errors.Is(err, os.ErrNotExist)
29}
30
31func TestDownloadProcess(t *testing.T) {
32	random := randomString(5)
33	tmp := fmt.Sprintf("/tmp/%s", random)
34	link := "https://www.youtube.com/watch?v=zGDzdps75ns"
35	yt.RunYtDlpProcess(link, tmp)
36
37	full_tmp_path := fmt.Sprintf("%s/Small short test video.webm", tmp)
38	assert.True(t, exists(full_tmp_path), "it worked?")
39
40	e := os.Remove(full_tmp_path)
41	if e != nil {
42		assert.FailNow(t, "File not removed properly")
43	}
44
45}