aboutsummaryrefslogtreecommitdiff
path: root/manager_test.go
diff options
context:
space:
mode:
authorGabriel A. Giovanini <mail@gabrielgio.me>2022-06-13 21:03:34 +0200
committerGabriel A. Giovanini <mail@gabrielgio.me>2022-06-13 21:07:54 +0200
commitf1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5 (patch)
tree7d9fe5031671cdf5fd8da3e031966c72a358942e /manager_test.go
parentf13a07aa433298de91e1c4aff68f72be6d851be2 (diff)
downloadmdir-f1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5.tar.gz
mdir-f1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5.tar.bz2
mdir-f1fd665089dd6b0a1fa4fc72a64db3cbf0b6d5f5.zip
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.
Diffstat (limited to 'manager_test.go')
-rw-r--r--manager_test.go45
1 files changed, 45 insertions, 0 deletions
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")
+ }
+
+}