| Conditions | 1 |
| Total Lines | 62 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | package s3 |
||
| 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 |