-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathobject_test.go
More file actions
39 lines (34 loc) · 1.11 KB
/
object_test.go
File metadata and controls
39 lines (34 loc) · 1.11 KB
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
package storage
import (
"testing"
"github.com/arschles/assert"
s3 "github.com/minio/minio-go"
)
const (
objKey = "myobj"
)
func TestObjectExistsSuccess(t *testing.T) {
objInfo := s3.ObjectInfo{Key: objKey, Err: nil, Size: 1234}
statter := &FakeObjectStatter{
Fn: func(string, string) (s3.ObjectInfo, error) {
return objInfo, nil
},
}
exists, err := ObjectExists(statter, bucketName, objKey)
assert.NoErr(t, err)
assert.True(t, exists, "object not found when it should be present")
assert.Equal(t, len(statter.Calls), 1, "number of StatObject calls")
assert.Equal(t, statter.Calls[0].BucketName, bucketName, "bucket name")
assert.Equal(t, statter.Calls[0].ObjectKey, objKey, "object key")
}
func TestObjectExistsNoObject(t *testing.T) {
statter := &FakeObjectStatter{
Fn: func(string, string) (s3.ObjectInfo, error) {
return s3.ObjectInfo{}, s3.ErrorResponse{Code: noSuchKeyCode}
},
}
exists, err := ObjectExists(statter, bucketName, objKey)
assert.NoErr(t, err)
assert.False(t, exists, "object found when it should be missing")
assert.Equal(t, len(statter.Calls), 1, "number of StatObject calls")
}