-
Notifications
You must be signed in to change notification settings - Fork 1
/
writebytes_test.go
42 lines (34 loc) · 782 Bytes
/
writebytes_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
package main
import (
"bytes"
"io/ioutil"
"os"
"testing"
)
func TestWriteBytes(t *testing.T) {
fromName := "test_files/small.txt"
fromFile, err := os.Open(fromName)
if err != nil {
t.Error("Can't open small.txt")
}
defer fromFile.Close()
tmpFile, err := ioutil.TempFile("", "output")
if err != nil {
t.Error(err)
}
defer os.Remove(tmpFile.Name())
maxBufferSize := int64(2)
bytesWritten, err := writeBytes(fromFile, 0, 34, tmpFile, maxBufferSize)
assertEqual(t, err, int64(34), bytesWritten, "")
fromBytes, err := ioutil.ReadFile(fromName)
if err != nil {
t.Error(err)
}
toBytes, err := ioutil.ReadFile(tmpFile.Name())
if err != nil {
t.Error(err)
}
if !bytes.Equal(fromBytes, toBytes) {
t.Error("toFile should be the same as fromFile")
}
}