Passed
Pull Request — master (#13)
by eval
01:32
created

s3.TestClientXAPIObject   B

Complexity

Conditions 1

Size

Total Lines 62
Code Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 45
nop 1
dl 0
loc 62
rs 8.8
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
package s3
2
3
import (
4
	"context"
5
	"testing"
6
7
	"github.com/matryer/is"
8
)
9
10
func TestClientXAPIObject(t *testing.T) {
11
	is := is.NewRelaxed(t)
12
	ctx := context.Background()
13
	svc := getTestClient(t)
14
	_ = createTestBucket(testPutBucketName)
15
16
	const path = "TestClientXAPIObject/test"
17
18
	// check non-existed object
19
	_, err := svc.XDeleteObjectFromPath(ctx, testPutBucketName, path)
20
	is.NoErr(err)
21
22
	ok, err := svc.XExistObject(ctx, testPutBucketName, path)
23
	is.NoErr(err)
24
	is.Equal(ok, false)
25
26
	resGet, err := svc.XGetObjectFromPath(ctx, testPutBucketName, path)
27
	is.NoErr(err)
28
	is.Equal(resGet.Exists, false)
29
30
	// check existed object
31
	resPut, err := svc.XPutObjectToPath(ctx, testPutBucketName, path, []byte("001"))
32
	is.NoErr(err)
33
	is.True(resPut.ETag != "") // ETag must be set
34
35
	ok, err = svc.XExistObject(ctx, testPutBucketName, path)
36
	is.NoErr(err)
37
	is.True(ok)
38
39
	resGet, err = svc.XGetObjectFromPath(ctx, testPutBucketName, path)
40
	is.NoErr(err)
41
	is.Equal(resGet.ETag, resPut.ETag) // ETag must be same
42
	byt, err := resGet.ToBytes()
43
	is.NoErr(err)
44
	is.Equal(byt, []byte("001")) // content must be updated
45
46
	// update existed object
47
	resPut, err = svc.XPutObjectToPath(ctx, testPutBucketName, path, []byte("002"))
48
	is.NoErr(err)
49
	is.True(resPut.ETag != "") // ETag must be set
50
51
	resGet, err = svc.XGetObjectFromPath(ctx, testPutBucketName, path)
52
	is.NoErr(err)
53
	is.Equal(resGet.ETag, resPut.ETag) // ETag must be same
54
	byt, err = resGet.ToBytes()
55
	is.NoErr(err)
56
	is.Equal(byt, []byte("002")) // content must be updated
57
58
	// check deleted object
59
	_, err = svc.XDeleteObjectFromPath(ctx, testPutBucketName, path)
60
	is.NoErr(err)
61
62
	ok, err = svc.XExistObject(ctx, testPutBucketName, path)
63
	is.NoErr(err)
64
	is.Equal(ok, false)
65
66
	resGet, err = svc.XGetObjectFromPath(ctx, testPutBucketName, path)
67
	is.NoErr(err)
68
	is.Equal(resGet.Exists, false)
69
70
	_, err = svc.XDeleteObjectFromPath(ctx, testPutBucketName, path)
71
	is.NoErr(err)
72
}
73