-
Notifications
You must be signed in to change notification settings - Fork 30
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
test: add unit tests for engine exec #180
Conversation
248aea4
to
3c115a2
Compare
f51945b
to
cc4ac84
Compare
d050eca
to
ef91b7c
Compare
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.
I would suggest to refactor the test and have into consideration table testing. Here's a starting point:
func TestEval_Labels() {
"when label has no name"
"when label exists"
"when label does not exist"
"when label is invalid"
}
func TestEval_Groups() {
"when group is valid"
"when group is invalid"
}
func TestEval_Rules() {
"when rule is valid"
"when rule is invalid"
}
func TestEval_Workflows() {
"when workflow is invalid" // e.g. rule is invalid
"when no workflow is activated"
"when one workflow is activated"
"when multiple workflows are activated"
"when workflow should always run"
"when workflow is activated and has extra actions"
}
You can check hasUnaddressedReviewThreads_test.go to have an idea.
Also, I would suggest to have a different reviewpad.yml
file for each test case in testdata/exec
. For instance:
- reviewpad_with_unmaned_label.yml
- reviewpad_with_valid_label.yml (this can be used for
"when label does not exist"
and"when label exists"
) - ...
- reviewpad_with_one_worfklow
- reviewpad_with_multiple_worfklows
WDYT?
ef91b7c
to
ebea37c
Compare
e051f1c
to
d444062
Compare
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.
Please have a look at the comments.
utils/file/file.go
Outdated
func LoadReviewpadFile(filepath string) ([]byte, error) { | ||
reviewpadFileData, err := os.ReadFile(filepath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return reviewpadFileData, nil | ||
} | ||
|
||
func ParseReviewpadFile(data []byte) (*engine.ReviewpadFile, error) { | ||
reviewpadFile := &engine.ReviewpadFile{} | ||
err := yaml.Unmarshal(data, &reviewpadFile) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// At the end of loading all imports from the file, its imports are reset to []engine.PadImport{}. | ||
// However, the parsing of the wanted reviewpad file, sets the imports to []engine.PadImport(nil). | ||
reviewpadFile.Imports = []engine.PadImport{} | ||
|
||
return reviewpadFile, nil | ||
} |
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.
Please review these functions.
d1f4d40
to
74656c6
Compare
Description
This pull request introduces the unit tests for engine exec and some extra mocks related to the pull request data.
During the development of the unit tests, it was encountered an error in the
CollectError
function where it wasn't being taken into account the*github.ErrorResponse
error type and this would cause an nil pointer dereference because theError()
method would be applied to this object which doesn't support such thing and so we need to manually get the error string in this case.Related issue
Closes #176
Type of change
Bug fix (non-breaking change which fixes an issue)
Improvements (non-breaking change without functionality)
How was this tested?
Ran
task test
cmd.Checklist
task check -f
and have no issues