Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update logging to print json as per mint log format #812

Merged
merged 9 commits into from
Sep 12, 2017

Conversation

nitisht
Copy link
Contributor

@nitisht nitisht commented Sep 7, 2017

See #779

if err = c.MakeBucket(bucketName, "eu-central-1"); err == nil {
logger().Fatal("Error: make bucket should should fail for", bucketName)
if err = c.MakeBucket(bucketName, region); err == nil {
failureLog(function, args, startTime, "", "Same bucket created twice", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Same bucket created twice" message sounds like as if the bucket is successfully created twice.
I think the message should simply say "Bucket already exists!"

@@ -283,57 +367,70 @@ func testPutObjectReadAt() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args["reader"] needs to be populated with reader value, since reader is one of the parameters for PutObject function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -283,57 +367,70 @@ func testPutObjectReadAt() {

// Save the data
objectName := randString(60, rand.NewSource(time.Now().UnixNano()), "")
args["objectName"] = objectName

// Object content type
objectContentType := "binary/octet-stream"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args["objectContentType"] needs to be populated with objectContentType value, since objectContentType is one of the parameters for PutObject function.

}
if st.Size != int64(sixtyFiveMiB) {
logger().Fatalf("Error: number of bytes in stat does not match, want %v, got %v\n",
sixtyFiveMiB, st.Size)
failureLog(function, args, startTime, "", "Number of bytes returned by PutObject does not match, want "+string(sixtyFiveMiB)+" got "+string(st.Size), err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Number of bytes returned by PutObject does not match, want ... => "Number of bytes returned by PutObject does not match GetObject. Expected ...

}
if st.ContentType != customContentType {
logger().Fatalf("Error: Expected and found content types do not match, want %v, got %v\n",
customContentType, st.ContentType)
failureLog(function, args, startTime, "", "ContentType does not match, want "+customContentType+" got "+st.ContentType, err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... match, want ... => ... match. Expected ...

}
if err := r.Close(); err == nil {
logger().Fatal("Error: object is already closed, should return error")
failureLog(function, args, startTime, "", "Object already closed, should respond with error", err).Fatal()
Copy link
Contributor

@ebozduman ebozduman Sep 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err here is nil. So, there is no point of printing it in the failure log.
failureLog(function, args, startTime, "", "Object already closed, should respond with error", err).Fatal()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has not been an answered yet.

_, err = c.PutObject(bucketName, objectName, reader, "application/octet-stream")
if err == nil {
logger().Fatal("Error: PutObject should fail.")
failureLog(function, args, startTime, "", "PutObject should fail", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err is nil. No point in logging it in.
failureLog(function, args, startTime, "", "PutObject should fail"~~, err~~).Fatal()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has not been answered yet.

}
if !strings.Contains(err.Error(), "proactively closed to be verified later") {
logger().Fatal("Error:", err)
failureLog(function, args, startTime, "", "Error string not found in PutObject output", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to say Error. It is fatal log and it is obvious that there is a problem:
failureLog(function, args, startTime, "", "Error sString not found in PutObject output", err).Fatal()

logger().Info()
// initialize logging params
startTime := time.Now()
function := "PutObject(bucketName, objectName, reader, contentType)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We test ListPartiallyUploaded functionality here. So, the function should be set to ListIncompleteUploads(bucketName, objectName, isRecursive, doneCh)

}
if st.Size != int64(bufSize) {
logger().Fatalf("Error: number of bytes in stat does not match, want %v, got %v\n",
bufSize, st.Size)
failureLog(function, args, startTime, "", "Number of bytes read does not match, want "+string(int64(bufSize))+" got "+string(st.Size), err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... match, want ... => ... match. Expected ...

}

st, err := r.Stat()
if err != nil {
logger().Fatal("Error:", err, bucketName, objectName)
failureLog(function, args, startTime, "", "GetObject failed", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"GetObject failed" => "Stat failed"

}
if st.Size != int64(bufSize) {
logger().Fatalf("Error: number of bytes in stat does not match, want %v, got %v\n",
bufSize, st.Size)
failureLog(function, args, startTime, "", "Number of bytes in stat does not match, want "+string(int64(bufSize))+", got "+string(st.Size), err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... match, want ... => ... match. Expected ...

}
if m != len(buf2) {
logger().Fatalf("Error: ReadAt read shorter bytes before reaching EOF, want %v, got %v\n", m, len(buf2))
failureLog(function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, want "+string(len(buf2))+", got "+string(m), err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... match, want ... => ... match. Expected ...

}
if m != len(buf3) {
logger().Fatalf("Error: ReadAt read shorter bytes before reaching EOF, want %v, got %v\n", m, len(buf3))
failureLog(function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, want "+string(len(buf3))+", got "+string(m), err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... match, want ... => ... match. Expected ...

}
if m != len(buf4) {
logger().Fatalf("Error: ReadAt read shorter bytes before reaching EOF, want %v, got %v\n", m, len(buf4))
failureLog(function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, want "+string(len(buf4))+", got "+string(m), err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... match, want ... => ... match. Expected ...

}
}
if m != len(buf5) {
logger().Fatalf("Error: ReadAt read shorter bytes before reaching EOF, want %v, got %v\n", m, len(buf5))
failureLog(function, args, startTime, "", "ReadAt read shorter bytes before reaching EOF, want "+string(len(buf5))+", got "+string(m), err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... match, want ... => ... match. Expected ...

}

policy := minio.NewPostPolicy()

if err := policy.SetBucket(""); err == nil {
logger().Fatalf("Error: %s", err)
failureLog(function, args, startTime, "", "SetBucket failed", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message is wrong. SetBucket is supposed to fail, but it did not return with an error message. So, this is a negative testing and "SetBucket failed" message here is misleading. The failureLog is supposed to be something like:
failureLog(function, args, startTime, "", "SetBucket did not fail for invalid bucket name").Fatal()

The same comment is also valid for the following line numbers:
1714, 1717, 1720, 1723, 1726, 1832, 1836, 1840, 1844, 1849, 1907, 2687, 2944, 3723, 3727, 3731, 3735, and 3797

}
if err = c.MakeBucket(bucketName, "eu-west-1"); err == nil {
logger().Fatal("Error: make bucket should should fail for", bucketName)
failureLog(function, args, startTime, "", "Make bucket should should fail", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo:
should should => should
But it is better to modify the error message since this is negative testing, probably like:
failureLog(function, args, startTime, "", "Bucket already exists").Fatal()

}
if err := r.Close(); err == nil {
logger().Fatal("Error: object is already closed, should return error")
failureLog(function, args, startTime, "", "Object is already closed, should return error", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point of logging nill error message, err:
failureLog(function, args, startTime, "", "Object is already closed, should return error", err).Fatal()

_, err = c.PutObject(bucketName, objectName, reader, "application/octet-stream")
if err == nil {
logger().Fatal("Error: PutObject should fail.")
failureLog(function, args, startTime, "", "PutObject should fail", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point of logging nill error message, err:
failureLog(function, args, startTime, "", "PutObject should fail", err).Fatal()

}
_, err = r.Seek(offset, 2)
if err == nil {
logger().Fatal("Error: seek on positive offset for whence '2' should error out")
failureLog(function, args, startTime, "", "Seek on positive offset for whence '2' should error out", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point of logging nill error message, err:
failureLog(function, args, startTime, "", "Seek on positive offset for whence '2' should error out", err).Fatal()

}

if err := c.ComposeObject(dst, srcSlice); err == nil {
logger().Fatal("Error was expected.")
failureLog(function, args, startTime, "", "Expected error in ComposeObject", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point of logging nill error message, err:
failureLog(function, args, startTime, "", "Expected error in ComposeObject", err).Fatal()

}
// 3. ComposeObject call should fail.
if err := c.ComposeObject(dst, []minio.SourceInfo{badSrc}); err == nil {
logger().Fatal("Error was expected.")
failureLog(function, args, startTime, "", "ComposeObject expected to fail", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point of logging nill error message, err:
failureLog(function, args, startTime, "", "ComposeObject expected to fail", err).Fatal()

}
err = c.RemoveBucket(bucketName)
if err == nil {
logger().Fatal("Error:")
failureLog(function, args, startTime, "", "RemoveBucket should fail as bucket does not exist", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point of logging nill error message, err:
failureLog(function, args, startTime, "", "RemoveBucket should fail as bucket does not exist", err).Fatal()

}
if err := r.Close(); err == nil {
logger().Fatal("Error: object is already closed, should return error")
failureLog(function, args, startTime, "", "Already closed object. No error returned", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err is nil. No point in logging it in.
failureLog(function, args, startTime, "", "Supposed to error out for the already closed object"~~, err~~).Fatal()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has not been answered yet.

_, err = c.PutObject(bucketName, objectName, reader, "application/octet-stream")
if err == nil {
logger().Fatal("Error: PutObject should fail.")
failureLog(function, args, startTime, "", "PutObject should fail", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err is nil. No point in logging it in.
failureLog(function, args, startTime, "", "PutObject was supposed to fail"~~, err~~).Fatal()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has not been answered yet.

@nitisht
Copy link
Contributor Author

nitisht commented Sep 9, 2017

@ebozduman updated the PR with correct error messages for negative test cases. For cases related to your comment

No point of logging nill error message, err:
failureLog(function, args, startTime, "", "RemoveBucket should fail as bucket does not exist", err).Fatal()

I have updated the logging function to not log error if its nil. Ref:
https://github.com/minio/minio-go/pull/812/files#diff-2b25d2aeef5dac13377316ffcd8ce169R102

}
if err := r.Close(); err == nil {
logger().Fatal("Error: object is already closed, should return error")
failureLog(function, args, startTime, "", "Object already closed, should respond with error", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has not been an answered yet.

_, err = c.PutObject(bucketName, objectName, reader, "application/octet-stream")
if err == nil {
logger().Fatal("Error: PutObject should fail.")
failureLog(function, args, startTime, "", "PutObject should fail", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has not been answered yet.

}
if err := r.Close(); err == nil {
logger().Fatal("Error: object is already closed, should return error")
failureLog(function, args, startTime, "", "Already closed object. No error returned", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has not been answered yet.

_, err = c.PutObject(bucketName, objectName, reader, "application/octet-stream")
if err == nil {
logger().Fatal("Error: PutObject should fail.")
failureLog(function, args, startTime, "", "PutObject should fail", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has not been answered yet.

}

policy := minio.NewPostPolicy()

if err := policy.SetBucket(""); err == nil {
logger().Fatalf("Error: %s", err)
failureLog(function, args, startTime, "", "SetBucket did not fail for invalid conditions", err).Fatal()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about these negative tests between lines 1711~1723?
The same err == nil comment also applies here.

@deekoder deekoder merged commit a0478d7 into minio:master Sep 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants