-
Notifications
You must be signed in to change notification settings - Fork 11
feat: additional tests for higher code coverage #170
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
gmegidish
wants to merge
4
commits into
main
Choose a base branch
from
feat-additional-tests
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
|
|
@@ -5,3 +5,4 @@ screenshot.png | |
| **/coverage*.out | ||
| **/coverage*.html | ||
| test/coverage | ||
| coverage/ | ||
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
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 |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| package daemon | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
| "os" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/sevlyar/go-daemon" | ||
| ) | ||
|
|
||
| const ( | ||
| // DaemonEnvVar is the environment variable that marks a daemon child process | ||
| DaemonEnvVar = "MOBILECLI_DAEMON_CHILD" | ||
|
|
||
| // shutdownRequestID is the JSON-RPC request ID for shutdown commands | ||
| shutdownRequestID = 1 | ||
| ) | ||
|
|
||
| // Daemonize detaches the process and returns the child process handle | ||
| // If the returned process is nil, this is the child process | ||
| // If the returned process is non-nil, this is the parent process | ||
| func Daemonize() (*os.Process, error) { | ||
| // no PID file needed | ||
| // we don't want log file, server handles its own logging | ||
| ctx := &daemon.Context{ | ||
| PidFileName: "", | ||
| PidFilePerm: 0, | ||
| LogFileName: "", | ||
| LogFilePerm: 0, | ||
| WorkDir: "/", | ||
| Umask: 027, | ||
| Args: os.Args, | ||
| Env: append(os.Environ(), fmt.Sprintf("%s=1", DaemonEnvVar)), | ||
| } | ||
|
|
||
| child, err := ctx.Reborn() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to daemonize: %w", err) | ||
| } | ||
|
|
||
| return child, nil | ||
| } | ||
|
|
||
| // IsChild returns true if this is the daemon child process | ||
| func IsChild() bool { | ||
| return os.Getenv(DaemonEnvVar) == "1" | ||
| } | ||
|
|
||
| // KillServer connects to the server and sends a shutdown command via JSON-RPC | ||
| func KillServer(addr string) error { | ||
| // normalize address to match server's format | ||
| // if no colon, assume it's a bare port number | ||
| if !strings.Contains(addr, ":") { | ||
| // validate it's a number | ||
| if _, err := strconv.Atoi(addr); err == nil { | ||
| addr = ":" + addr | ||
| } | ||
| } | ||
|
|
||
| // if address starts with colon, prepend localhost | ||
| if strings.HasPrefix(addr, ":") { | ||
| addr = "localhost" + addr | ||
| } | ||
|
|
||
| // prepend http:// scheme | ||
| addr = "http://" + addr | ||
|
|
||
| // create JSON-RPC request | ||
| reqBody := map[string]interface{}{ | ||
| "jsonrpc": "2.0", | ||
| "method": "server.shutdown", | ||
| "id": shutdownRequestID, | ||
| } | ||
|
|
||
| jsonData, err := json.Marshal(reqBody) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to marshal request: %w", err) | ||
| } | ||
|
|
||
| // send request | ||
| client := &http.Client{Timeout: 10 * time.Second} | ||
| req, err := http.NewRequest(http.MethodPost, addr+"/rpc", bytes.NewBuffer(jsonData)) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to create request: %w", err) | ||
| } | ||
| req.Header.Set("Content-Type", "application/json") | ||
|
|
||
| resp, err := client.Do(req) | ||
| if err != nil { | ||
| if strings.Contains(err.Error(), "connection refused") { | ||
| return fmt.Errorf("server is not running on %s", addr) | ||
| } | ||
| return fmt.Errorf("failed to connect to server: %w", err) | ||
| } | ||
|
|
||
| // check response | ||
| if resp.StatusCode != http.StatusOK { | ||
| _ = resp.Body.Close() | ||
| return fmt.Errorf("server returned error: %s", resp.Status) | ||
| } | ||
|
|
||
| return resp.Body.Close() | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
e2e_testis not a dependency ofpublish— is this intentional?The
publishjob (line 234) depends on[build_on_windows, build_on_linux, build_on_macos, server_test]but does not includee2e_test. This means a release can be published even when E2E tests fail. If this is intentional (e.g., because self-hosted runner availability is unreliable), consider adding a comment to document the decision. Otherwise, adde2e_testto the needs list.🤖 Prompt for AI Agents