-
Notifications
You must be signed in to change notification settings - Fork 7
fix: make app failed if a container is stopped #116
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
Open
giulio93
wants to merge
9
commits into
main
Choose a base branch
from
add_stopped_state_to_app_status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4105b65
add status stopped
giulio93 99354fd
Apply suggestion from @lucarin91
giulio93 a09d652
Add state failed
giulio93 c9deb5f
States
giulio93 25d90c6
revert
giulio93 906154a
containerState struct with Status and StatusMessage
giulio93 fe0cced
handle ct state in helpers
giulio93 76faefe
add status message to
giulio93 acba544
check function in status
giulio93 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,60 +20,75 @@ import ( | |
|
|
||
| "github.com/docker/docker/api/types/container" | ||
| "github.com/stretchr/testify/require" | ||
| "go.bug.st/f" | ||
| ) | ||
|
|
||
| func TestParseAppStatus(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| containerState []container.ContainerState | ||
| statusMessage []string | ||
| want Status | ||
| }{ | ||
| { | ||
| name: "everything running", | ||
| containerState: []container.ContainerState{container.StateRunning, container.StateRunning}, | ||
| statusMessage: []string{"Up 5 minutes", "Up 10 minutes"}, | ||
| want: StatusRunning, | ||
| }, | ||
| { | ||
| name: "everything stopped", | ||
| containerState: []container.ContainerState{container.StateCreated, container.StatePaused, container.StateExited}, | ||
| statusMessage: []string{"Created", "Paused", "Exited (137)"}, | ||
| want: StatusStopped, | ||
| }, | ||
| { | ||
| name: "failed container", | ||
| containerState: []container.ContainerState{container.StateRunning, container.StateDead}, | ||
| statusMessage: []string{"Up 5 minutes", "Dead"}, | ||
| want: StatusFailed, | ||
| }, | ||
| { | ||
| name: "failed container takes precedence over stopping and starting", | ||
| containerState: []container.ContainerState{container.StateRunning, container.StateDead, container.StateRemoving, container.StateRestarting}, | ||
| statusMessage: []string{"Up 5 minutes", "Dead", "Removing", "Restarting"}, | ||
| want: StatusFailed, | ||
| }, | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should add a test for the new check
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created as status failed! |
||
| name: "stopping", | ||
| containerState: []container.ContainerState{container.StateRunning, container.StateRemoving}, | ||
| statusMessage: []string{"Up 5 minutes", "Removing"}, | ||
| want: StatusStopping, | ||
| }, | ||
| { | ||
| name: "stopping takes precedence over starting", | ||
| containerState: []container.ContainerState{container.StateRunning, container.StateRestarting, container.StateRemoving}, | ||
| statusMessage: []string{"Up 5 minutes", "Restarting", "Removing"}, | ||
| want: StatusStopping, | ||
| }, | ||
| { | ||
| name: "starting", | ||
| containerState: []container.ContainerState{container.StateRestarting, container.StateExited}, | ||
| statusMessage: []string{"Restarting", "Exited (129)"}, | ||
| want: StatusStarting, | ||
| }, | ||
| { | ||
| name: "failed", | ||
| containerState: []container.ContainerState{container.StateRestarting, container.StateExited}, | ||
| statusMessage: []string{"Restarting", "Exited (0)"}, | ||
| want: StatusFailed, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| input := f.Map(tc.containerState, func(c container.ContainerState) container.Summary { | ||
| return container.Summary{ | ||
| var input []container.Summary | ||
| for i, c := range tc.containerState { | ||
| input = append(input, container.Summary{ | ||
| Labels: map[string]string{DockerAppPathLabel: "path1"}, | ||
| State: c, | ||
| } | ||
| }) | ||
| Status: tc.statusMessage[i], | ||
| }) | ||
| } | ||
| res := parseAppStatus(input) | ||
| require.Len(t, res, 1) | ||
| require.Equal(t, tc.want, res[0].Status) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As I said in a previous review
I would like to move the parsing function
checkExitCodeto theStatusFromDockerStatemapping function. I think it is clearer to have a single function for mapping docker container status to our app status, instead of adding a special check here.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.
https://github.com/arduino/arduino-app-cli/pull/116/files#diff-6fe2dade2880e479db573af3bd075e48246ad3683231b5b2cd44d8341145751c
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've finally change it to a check bool function, that parse and check that the code is grater than 128, so we now if it was killed or it failed