-
Notifications
You must be signed in to change notification settings - Fork 315
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
Validate Test section to avoid panic if test section is not populated properly #4309
Conversation
Signed-off-by: Andrea Falzetti <andrea@okteto.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4309 +/- ##
==========================================
- Coverage 43.22% 43.20% -0.02%
==========================================
Files 371 371
Lines 30027 30040 +13
==========================================
Hits 12979 12979
- Misses 15924 15937 +13
Partials 1124 1124 |
What other tools or languages behaves when no tests are defined? I mean, for example image I execute |
I you run Once you init the project ( |
hasAtLeastOne := false | ||
for _, t := range test { | ||
if t != nil { | ||
hasAtLeastOne = 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.
I think this code could be simplified by removing the bool and returning nil as soon as we detect there is one without the break. WDYT?
hasAtLeastOne = true | |
for _, t := range test { | |
if t != nil { | |
return 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.
@jLopezbarb I personally find more readable and easier to maintain the current code, because having return nil
means we cannot add additional validations after this check. If we want to add one extra check in the future, we need to refactor and add the bool again. Your suggestion uses less memory but in our context, I think the benefits are minimal compared to keeping the code easy to change. WDYT?
@andreafalzetti I know that is out of scope of this PR but I also found one more panic that maybe we could fix it on this PR.
build:
backend:
context: .
test:
backend:
image: okteto/golang:1
context: backend
commands:
- name: command1
command: echo "this is command 1"
- name: command2
command: echo "this is command 2"
|
Good catch! As discussed offline, we'll tackle that case in DEV-359 |
Proposed changes
Fixes DEV-348
In this PR we're adding a validation layer for the Test section of the Okteto Manifest. Currently, passing empty section, or empty test throws panics.
Important Note: Curently, if no tests are configured, the Okteto CLI will just deploy the application. But there is no logs or anything that informs the user that "nothing" has been done test-wise. With this change we make sure they are informed if they run
test
without configuring them. It also exit non-zero, so if this was intended to always exit 0 (for CI reasons for example), I can make it a warning.BEFORE (Empty
![Screenshot 2024-05-22 at 09 36 47](https://private-user-images.githubusercontent.com/2318450/332704666-bf828c43-f639-458f-9f3c-61f8df1c2b06.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0MjM1MjQsIm5iZiI6MTcyMTQyMzIyNCwicGF0aCI6Ii8yMzE4NDUwLzMzMjcwNDY2Ni1iZjgyOGM0My1mNjM5LTQ1OGYtOWYzYy02MWY4ZGYxYzJiMDYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MTlUMjEwNzA0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Njc1MWY5OGI0YTdiYzY4ODVlODY3NjE3ZTc1NjVlZjJjMTlkYjBmYmQyMzliMzRmOGI4Mjk5ZTY1YjhlMDRlYyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.gJPoi2vagsGEjiGD3v41tJ-iTZ04XsrNUCifHQVkJgM)
test
section)NOW
![Screenshot 2024-05-22 at 09 38 54](https://private-user-images.githubusercontent.com/2318450/332704680-c5e08fda-cac1-40d1-a090-181702e61f0b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE0MjM1MjQsIm5iZiI6MTcyMTQyMzIyNCwicGF0aCI6Ii8yMzE4NDUwLzMzMjcwNDY4MC1jNWUwOGZkYS1jYWMxLTQwZDEtYTA5MC0xODE3MDJlNjFmMGIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MTlUMjEwNzA0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YTRiYmVhYmFhYjNkZWNkMzE3OWM1ZDVhMTNhNTE5ZjUxNjkwYTZiYTU5ZmFhNGI4YzM1ZjAwMDMzMzMxNTRkMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.ybEEpu1EZD0zWBF030KiKjPgE1hux6UhZs7LNrS0b-E)
How to validate
Using the following manifests, and run
okteto test
Missing
test
sectionEmpty
test
sectionEmpty test
CLI Quality Reminders 🔧
For both authors and reviewers: