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") } }