-
Notifications
You must be signed in to change notification settings - Fork 0
/
tinychunk_test.go
69 lines (50 loc) · 1.24 KB
/
tinychunk_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package tinychunk_test
import (
"fmt"
. "github.com/BitlyTwiser/tinychunk"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"log"
"os"
"testing"
)
// Simply write files, then delete them.
func fileFunc(fileData []byte) error {
err := os.WriteFile(fmt.Sprintf("./assets/test/%v.txt", uuid.NewString()), fileData, 0700)
if err != nil {
return err
}
return nil
}
func openFile(fileName string) []byte {
file, err := os.ReadFile(fmt.Sprintf("./assets/%v", fileName))
if err != nil {
log.Printf("Error opening file for test: %v", err.Error())
os.Exit(1)
}
return file
}
func TestOneMegabyteChunking(t *testing.T) {
t.Log("chunking 1MB file")
file := openFile("testFile.txt")
err := Chunk(file, 1, fileFunc)
assert.Nil(t, err)
}
func TestTwoMegabyteChunking(t *testing.T) {
t.Log("chunking 2MB file")
file := openFile("testFile.txt")
err := Chunk(file, 2, fileFunc)
assert.Nil(t, err)
}
func TestThreeMegabyteChunking(t *testing.T) {
t.Log("chunking 3MB file")
file := openFile("testFile.txt")
err := Chunk(file, 3, fileFunc)
assert.Nil(t, err)
}
func TestFourMegabyteChunking(t *testing.T) {
t.Log("chunking 4MB file")
file := openFile("testFile.txt")
err := Chunk(file, 4, fileFunc)
assert.Nil(t, err)
}