-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload_test.go
53 lines (42 loc) · 1.36 KB
/
upload_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
package rest
import (
"context"
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"io"
"log"
"testing"
)
type emptyReader struct{}
func (*emptyReader) Read(b []byte) (int, error) {
return 0, io.EOF
}
func TestUpload(t *testing.T) {
// input file (16MB, non seekable)
var input io.Reader
input = &io.LimitedReader{R: rand.Reader, N: 16 * 1024 * 1024}
// compute sha256 of bytes we send
hash := sha256.New()
input = io.TeeReader(input, hash)
ctx := context.Background()
res, err := Upload(ctx, "Misc/Debug:testUpload", "POST", Param{"filename": "test.bin"}, input, "application/octet-stream")
//res, err := Upload(ctx, "Shell/Bit:upload", "POST", Param{"filename": "test.bin"}, input, "application/octet-stream")
if err != nil {
t.Fatalf("failed to do upload: %s", err)
}
log.Printf("expected hash = %s", hex.EncodeToString(hash.Sum(nil)))
log.Printf("res = %s", res.Data)
}
func TestUploadEmpty(t *testing.T) {
// input file (0 non seekable)
var input io.Reader
input = &emptyReader{}
ctx := context.Background()
res, err := Upload(ctx, "Misc/Debug:testUpload", "POST", Param{"filename": "empty.bin"}, input, "application/octet-stream")
//res, err := Upload(ctx, "Shell/Bit:upload", "POST", Param{"filename": "test.bin"}, input, "application/octet-stream")
if err != nil {
t.Fatalf("failed to do upload: %s", err)
}
log.Printf("res = %s", res.Data)
}