mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-06-06 08:01:08 +08:00
feat: add support for splitting large files into parts for Telegram storage, #156
This commit is contained in:
55
storage/telegram/split_test.go
Normal file
55
storage/telegram/split_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCreateSplitZip(t *testing.T) {
|
||||
input := "tests/testfile.dat"
|
||||
file, err := os.Open(input)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open test file: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
fileName := filepath.Base(input)
|
||||
fileInfo, err := file.Stat()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to stat test file: %v", err)
|
||||
}
|
||||
fileSize := fileInfo.Size()
|
||||
|
||||
tests := []struct {
|
||||
partSize int64
|
||||
output string
|
||||
}{
|
||||
{partSize: int64(1024 * 1024 * 500), output: "tests/split_test_output_500MB"},
|
||||
{partSize: int64(1024 * 1024 * 100), output: "tests/split_test_output_100MB"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
err = CreateSplitZip(t.Context(), file, fileSize, fileName, tt.output, tt.partSize)
|
||||
if err != nil {
|
||||
t.Fatalf("CreateSplitZip failed: %v", err)
|
||||
}
|
||||
matched, err := filepath.Glob(tt.output + ".z*")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to glob split files: %v", err)
|
||||
}
|
||||
if len(matched) == 0 {
|
||||
t.Fatalf("no split files found")
|
||||
}
|
||||
t.Logf("Created %d split files", len(matched))
|
||||
for _, f := range matched {
|
||||
info, err := os.Stat(f)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to stat file %s: %v", f, err)
|
||||
}
|
||||
if info.Size() > tt.partSize {
|
||||
t.Errorf("file %s exceeds part size: %d > %d", f, info.Size(), tt.partSize)
|
||||
}
|
||||
t.Logf(" - %s (%d bytes)", f, info.Size())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user