-
Notifications
You must be signed in to change notification settings - Fork 0
fix(cli): home heartbeat fetches one client, not the whole account (#338) #339
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
Merged
+166
−68
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
102817b
fix(cli): home heartbeat fetches one client, not the whole account (#…
saadqbal eb67e66
test(cli): point client-status stubs at the /edge-device/{id}/ detail…
saadqbal 4d633c7
test(cli): point delete status-guard stubs at /edge-device/{id}/ too
saadqbal c1f50ea
fix(cli): non-numeric active client id is not-found, not a retryable …
saadqbal 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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "testing" | ||
| ) | ||
|
|
||
| // TestGetClient covers the single-client detail fetch (GET /edge-device/{id}/) | ||
| // that backs the home-screen heartbeat (cli#338): a 2xx decodes one client, a | ||
| // 404 is (nil, nil) — "no such client", not an error — and any other non-2xx is | ||
| // an APIError. It also pins the path so the heartbeat can't regress to a list. | ||
| func TestGetClient(t *testing.T) { | ||
| t.Run("2xx decodes a single client + hits the detail path", func(t *testing.T) { | ||
| c := stubClient(t, func(w http.ResponseWriter, r *http.Request) { | ||
| if r.URL.Path != "/edge-device/1070/" { | ||
| t.Errorf("path = %q, want /edge-device/1070/ (detail route, not the list)", r.URL.Path) | ||
| } | ||
| _, _ = w.Write([]byte(`{"id":1070,"first_name":"asad-macbook","status":1,"namespace":"asad-macbook-3"}`)) | ||
| }) | ||
| pc, err := c.GetClient(context.Background(), 1070) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if pc == nil || pc.ID != 1070 || pc.Status != 1 { | ||
| t.Fatalf("GetClient = %+v, want id=1070 status=1", pc) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("404 -> (nil, nil), not an error", func(t *testing.T) { | ||
| c := stubClient(t, func(w http.ResponseWriter, _ *http.Request) { w.WriteHeader(http.StatusNotFound) }) | ||
| pc, err := c.GetClient(context.Background(), 999) | ||
| if pc != nil || err != nil { | ||
| t.Fatalf("404 must be (nil, nil); got (%+v, %v)", pc, err) | ||
| } | ||
| }) | ||
|
|
||
| t.Run("non-2xx (500) -> APIError", func(t *testing.T) { | ||
| c := stubClient(t, func(w http.ResponseWriter, _ *http.Request) { | ||
| w.WriteHeader(http.StatusInternalServerError) | ||
| _, _ = w.Write([]byte(`{"detail":"boom"}`)) | ||
| }) | ||
| if _, err := c.GetClient(context.Background(), 1); err == nil { | ||
| t.Error("a 500 must return an error") | ||
| } | ||
| }) | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.