-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3_test.go
57 lines (44 loc) · 1.3 KB
/
s3_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
// Package awsutils provides some helper function for common aws task.
package awsutils
import (
"errors"
"testing"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/service/s3/s3iface"
)
/*Mock stuff*/
type mockedS3Client struct {
s3iface.S3API
}
func (s *mockedS3Client) ListObjectsV2(*s3.ListObjectsV2Input) (*s3.ListObjectsV2Output, error) {
key := "someKey"
contents := []*s3.Object{&s3.Object{Key: &key}}
return &s3.ListObjectsV2Output{Contents: contents}, nil
}
func (s *mockedS3Client) GetObject(*s3.GetObjectInput) (*s3.GetObjectOutput, error) {
return nil, errors.New("bad stuff! Try next file")
}
func TestDownloadBucket(t *testing.T) {
b := Bucket{}
err := b.DownloadBucket(nil)
if err.Error() != messageClientNotDefined {
t.Errorf("Expected error :%s, and got %s", messageClientNotDefined, err.Error())
}
b = NewBucket(&mockedS3Client{}, "Bucket", "temp")
err = b.DownloadBucket(nil)
if err != nil {
t.Errorf(err.Error())
}
}
func TestUploadEmptyBucket(t *testing.T) {
b := Bucket{}
err := b.UploadBucket()
if err.Error() != messageClientNotDefined {
t.Errorf("Expected error :%s, and got %s", messageClientNotDefined, err.Error())
}
b = NewBucket(&mockedS3Client{}, "Bucket", "NotADir")
err = b.UploadBucket()
if err != nil {
t.Errorf(err.Error())
}
}