-
Notifications
You must be signed in to change notification settings - Fork 1.1k
est(pkg/ddc/alluxio): add tests for generateDataBackupValueFile #5480
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: master
Are you sure you want to change the base?
est(pkg/ddc/alluxio): add tests for generateDataBackupValueFile #5480
Conversation
Summary of ChangesHello @hxrshxz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request modernizes the testing infrastructure for the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Hi @hxrshxz. Thanks for your PR. I'm waiting for a fluid-cloudnative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
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.
Code Review
This pull request successfully migrates the tests in pkg/ddc/alluxio/types_test.go from the standard Go testing library to the Ginkgo/Gomega framework. The migration is well-executed and follows Ginkgo best practices. A significant improvement is the addition of several new test cases that cover edge cases like empty tiered store levels and empty paths, which enhances the overall test coverage. I have one suggestion to further improve the test code's clarity by using constants for values that do not change across tests.
04ca299 to
b1b9db8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5480 +/- ##
==========================================
+ Coverage 56.76% 57.08% +0.31%
==========================================
Files 443 443
Lines 30735 30735
==========================================
+ Hits 17447 17544 +97
+ Misses 11734 11624 -110
- Partials 1554 1567 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
c1e25dd to
c4f1489
Compare
|
/gemini review |
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.
Code Review
This pull request adds unit tests for generateDataBackupValueFile, which is a great addition. The tests cover several important scenarios, including success cases and error handling for invalid inputs or missing resources. My review focuses on improving the existing tests by adding validation for the generated file's content, which is crucial for ensuring the function works as expected. I've provided a few suggestions to implement this content validation.
| testCases := []struct { | ||
| name string | ||
| dataBackup *datav1alpha1.DataBackup | ||
| runtime *datav1alpha1.AlluxioRuntime | ||
| dataset *datav1alpha1.Dataset | ||
| masterPod *corev1.Pod | ||
| expectError bool | ||
| errorMsg string | ||
| }{ |
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.
The tests currently only check for the existence of the generated value file, but not its content. To make the tests more robust, I suggest validating the content of the generated YAML file. You can achieve this by adding a new field expectValueCheck to the testCases struct, which will be a function to perform assertions on the unmarshalled data. You'll also need to import cdatabackup "github.com/fluid-cloudnative/fluid/pkg/databackup".
testCases := []struct {
name string
dataBackup *datav1alpha1.DataBackup
runtime *datav1alpha1.AlluxioRuntime
dataset *datav1alpha1.Dataset
masterPod *corev1.Pod
expectError bool
errorMsg string
expectValueCheck func(t *testing.T, values *cdatabackup.DataBackupValue)
}{| PodIP: "10.0.0.1", | ||
| }, | ||
| }, | ||
| expectError: 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.
Similarly, for the default case, you should add a check to ensure that the RunAs related values are not set when databackup.Spec.RunAs is nil.
expectError: false,
expectValueCheck: func(t *testing.T, values *cdatabackup.DataBackupValue) {
if values.UserInfo.User != 0 {
t.Errorf("expected default user, but got %d", values.UserInfo.User)
}
if values.InitUsers.Enabled {
t.Error("expected InitUsers to be disabled, but it was enabled")
}
},| PodIP: "10.0.0.1", | ||
| }, | ||
| }, | ||
| expectError: 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.
With the new expectValueCheck field, you can add specific checks for this test case to ensure the UserInfo and InitUsers fields are correctly set in the generated values.
expectError: false,
expectValueCheck: func(t *testing.T, values *cdatabackup.DataBackupValue) {
if values.UserInfo.User != 1000 {
t.Errorf("expected user 1000, got %d", values.UserInfo.User)
}
if values.UserInfo.Group != 1000 {
t.Errorf("expected group 1000, got %d", values.UserInfo.Group)
}
if !values.InitUsers.Enabled {
t.Error("expected InitUsers to be enabled")
}
},| } else { | ||
| defer os.Remove(valueFileName) | ||
| if _, err := os.Stat(valueFileName); os.IsNotExist(err) { | ||
| t.Errorf("value file %s was not created", valueFileName) | ||
| } | ||
| } |
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.
This logic should be updated to read the generated file, unmarshal it, and run the validation function. This completes the test enhancement for content validation. You'll need to add "os", "gopkg.in/yaml.v2", and cdatabackup "github.com/fluid-cloudnative/fluid/pkg/databackup" to your imports.
} else {
defer os.Remove(valueFileName)
if _, err := os.Stat(valueFileName); os.IsNotExist(err) {
t.Errorf("value file %s was not created", valueFileName)
}
if tc.expectValueCheck != nil {
data, err := os.ReadFile(valueFileName)
if err != nil {
t.Fatalf("failed to read value file: %v", err)
}
var values cdatabackup.DataBackupValue
err = yaml.Unmarshal(data, &values)
if err != nil {
t.Fatalf("failed to unmarshal value file: %v", err)
}
tc.expectValueCheck(t, &values)
}
}Signed-off-by: Harsh <harshmastic@gmail.com>
c4f1489 to
a580041
Compare
|



Ⅰ. Describe what this PR does
test(pkg/ddc/alluxio): add unit tests for generateDataBackupValueFile
Ⅱ. Does this pull request fix one issue?
part of #5407
Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.
Tiered Store Path Test Cases
RunAs(UID/GID) settings are correctly propagated to the value fileⅣ. Describe how to verify it
go test -v ./pkg/ddc/alluxio/... -run TestGenerateDataBackupⅤ. Special notes for reviews