mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-09 01:50:30 +00:00
feat: add download directory placeholders, category support (#1188)
This commit is contained in:
1 parent
9d9f1caaaa
commit
49b4d99b5e
31 files changed
+1204
-118
No files matched your search
@@ -1,8 +1,11 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDir(t *testing.T) {
|
||||
@@ -240,3 +243,75 @@ func TestReplaceInvalidFilename(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplacePathPlaceholders(t *testing.T) {
|
||||
now := time.Now()
|
||||
year := fmt.Sprintf("%d", now.Year())
|
||||
month := fmt.Sprintf("%02d", now.Month())
|
||||
day := fmt.Sprintf("%02d", now.Day())
|
||||
date := fmt.Sprintf("%s-%s-%s", year, month, day)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "empty path",
|
||||
path: "",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "no placeholders",
|
||||
path: "/home/user/Downloads",
|
||||
want: "/home/user/Downloads",
|
||||
},
|
||||
{
|
||||
name: "year placeholder",
|
||||
path: "/Downloads/%year%",
|
||||
want: "/Downloads/" + year,
|
||||
},
|
||||
{
|
||||
name: "month placeholder",
|
||||
path: "/Downloads/%month%",
|
||||
want: "/Downloads/" + month,
|
||||
},
|
||||
{
|
||||
name: "day placeholder",
|
||||
path: "/Downloads/%day%",
|
||||
want: "/Downloads/" + day,
|
||||
},
|
||||
{
|
||||
name: "date placeholder",
|
||||
path: "/Downloads/%date%",
|
||||
want: "/Downloads/" + date,
|
||||
},
|
||||
{
|
||||
name: "multiple placeholders",
|
||||
path: "/Downloads/%year%-%month%",
|
||||
want: "/Downloads/" + year + "-" + month,
|
||||
},
|
||||
{
|
||||
name: "mixed path with placeholders",
|
||||
path: "/home/user/Downloads/%year%/%month%/%day%",
|
||||
want: "/home/user/Downloads/" + year + "/" + month + "/" + day,
|
||||
},
|
||||
{
|
||||
name: "windows style path",
|
||||
path: "D:\\Downloads\\%year%-%month%",
|
||||
want: "D:\\Downloads\\" + year + "-" + month,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := ReplacePathPlaceholders(tt.path)
|
||||
if !strings.Contains(got, year) && tt.path != "" && strings.Contains(tt.path, "%year%") {
|
||||
t.Errorf("ReplacePathPlaceholders() = %v, want containing year %v", got, year)
|
||||
}
|
||||
if got != tt.want {
|
||||
t.Errorf("ReplacePathPlaceholders() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user