From f1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Mon, 13 Jun 2022 21:03:34 +0200 Subject: feat: Add poor implementation for the worker This is just me testing a bit how doworker works, while I learn of go/gin in the process. --- manager_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 manager_test.go (limited to 'manager_test.go') diff --git a/manager_test.go b/manager_test.go new file mode 100644 index 0000000..d0d2e35 --- /dev/null +++ b/manager_test.go @@ -0,0 +1,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") + } + +} -- cgit v1.2.3