feat: Add a command to stop the local stack - #5
Conversation
1afa56c to
50fe1ba
Compare
Code Review SummaryThis revision implements the requested 🚀 Key Improvements
💡 Minor Suggestions
|
| switch resp.StatusCode { | ||
| case http.StatusNoContent: | ||
| return nil | ||
| case http.StatusOK, http.StatusNotFound, http.StatusMethodNotAllowed: |
There was a problem hiding this comment.
The comment only explains the 200 case, but this branch also groups 404 and 405. Update it to describe all three unsupported statuses so future readers don't wonder why NotFound/MethodNotAllowed are handled here.
| case http.StatusOK, http.StatusNotFound, http.StatusMethodNotAllowed: | |
| case http.StatusOK, http.StatusNotFound, http.StatusMethodNotAllowed: | |
| // Only 204 acknowledges shutdown; 200/404/405 mean this agent does not support stop. |
|
|
||
| func (e *Unreachable) Unwrap() error { return e.Cause } | ||
|
|
||
| func IsConnectionRefused(err error) bool { |
There was a problem hiding this comment.
Exported functions should have a doc comment explaining their contract, especially since this is a new public helper used by the command package.
| func IsConnectionRefused(err error) bool { | |
| // IsConnectionRefused reports whether err represents an agent that is not | |
| // listening because the connection was refused. | |
| func IsConnectionRefused(err error) bool { | |
| var unreachable *Unreachable | |
| return errors.As(err, &unreachable) && errors.Is(unreachable.Cause, syscall.ECONNREFUSED) | |
| } |
| if Run([]string{"--agent", server.URL, "--timeout", "20ms", "stop"}, &out, &stderr) == 0 { | ||
| t.Fatal("a timed-out stop request succeeded") | ||
| } | ||
| if strings.Contains(out.String(), "already stopped") || stderr.Len() == 0 { |
There was a problem hiding this comment.
Checking that stderr is non-empty is weak. Assert the actual error message so the test fails with a clear diagnostic if the wrong error path is taken (for example, if a future change prints "already stopped" to stderr instead of stdout).
| if strings.Contains(out.String(), "already stopped") || stderr.Len() == 0 { | |
| if strings.Contains(out.String(), "already stopped") || !strings.Contains(stderr.String(), "could not stop SourceAnt") { | |
| t.Fatalf("stdout=%s stderr=%s", out.String(), stderr.String()) | |
| } |
Add a stop command for the local stack. Requires an agent release with shutdown support.