-
Notifications
You must be signed in to change notification settings - Fork 5
Added unit tests and E2E tests #418
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
base: main
Are you sure you want to change the base?
Conversation
anirudhbansal95
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Ankush. Reviewed the unit tests and the associated code. Yet to review the end to end tests.
| return fmt.Errorf("%s", delete_resp.Status) | ||
| if delete_resp.StatusCode == 404 { | ||
| return nil | ||
| } else if delete_resp.StatusCode != 204 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: else if can be removed from line 165 since we are returning in line 164
|
|
||
| t.Run("TestCreateUser_MissingUsername", func(t *testing.T) { | ||
| api := &admin.API{} | ||
| _, err := api.CreateUser(ctx, "", mockDisplayName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently we allow the display name to be empty, though not the user name. Is this the expected behaviour?
| api := admin.API{ | ||
| AccountName: "test", | ||
| } | ||
| accountName := api.AccountName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use api.GetAccountName() here and in the test below
| klog.ErrorS(err, "failed to delete user") | ||
| } | ||
|
|
||
| klog.InfoS("Successfully revoked access of user", "userName", req.GetAccountId(), "bucketName", req.GetBucketId()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we also need to update the bucket policy here to remove the user from it, like we updated the bucket policy to grant user access in the previous case?
| klog.InfoS("Deleting user", "id", req.GetAccountId()) | ||
|
|
||
| err := s.ntnxIamClient.RemoveUser(ctx, req.GetAccountId()) | ||
| err := s.NtnxIamClient.RemoveUser(ctx, req.GetAccountId()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does ignoring the error mean this is only a best-effort API to revoke user access from bucket, since it returns nil error even if there was an IAM issue for example? Is the caller fine with this behaviour?
| foundSID1 = true | ||
| assert.Equal(t, "Deny", string(ps.Effect)) | ||
| case "sid2": | ||
| foundSID2 = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also check that sid2 and sid3 have "Allow" effect
| ps.Allows() | ||
| assert.Equal(t, s3client.Effect("Allow"), ps.Effect) | ||
| ps.Effect = "Other" | ||
| ps.Allows() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Maybe add a comment that ps.Allows() doesn't modify an existing effect, if set.
| s := &s3client.S3Agent{Client: mock} | ||
| content, err := s.GetObjectInBucket("missing-bucket", "missing-key") | ||
| assert.Error(t, err) | ||
| assert.Equal(t, "ERROR_ OBJECT NOT FOUND", content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a specific format in which the object not found error should be returned? Or can it be something like: ERROR_OBJECT_NOT_FOUND or some other string?
anirudhbansal95
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Ankush. Took a look at the end to end tests. They look good in general with a few comments.
| return err | ||
| } | ||
|
|
||
| if bucket.Status.BucketReady == false { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if !bucket.Status.BucketReady
| return err | ||
| } | ||
|
|
||
| if bucket.Status.BucketReady == true { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if bucket.Status.BucketReady
| Expect(err).ToNot(HaveOccurred()) | ||
|
|
||
| // By("Checking if Bucket is created in the Objectstore backend") | ||
| err = s3Client.WaitUntilBucketExists(&s3.HeadBucketInput{Bucket: &failBucket.Name}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to call this function in other tests as well?
Summary:
This PR introduces a testing framework for the Nutanix COSI driver, including both unit tests and end-to-end (E2E) tests. In addition, several minor bugs discovered during test development have been addressed and resolved.
Changes:
Unit Tests:
E2E Tests:
CI/CD Pipeline:
Deployment Changes:
PC_SECRETnow only contains username and password credentials for the Prism Central in the previous format.PC_ENDPOINTinstead should have the full endpoint of the Prism Central.Fixes:
How to run tests?
Unit Tests:
Execute the following to run unit tests:
go test ./...To generate the coverage report and an HTML page to view the report:
go test -coverprofile=coverage.out ./... go tool cover -html=coverage.out -o coverage.htmlOpen the HTML file in any web browser to view the coverage of each file.
E2E Tests:
Execute the following to run E2E tests:
Check the README.md for more info.