Repository navigation
fix(catalog): accept the web catalog's health_probe so the next sync passes the strict-decode test #281
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
GeiserX
wants to merge
3
commits into
main
Choose a base branch
from
fix/catalog-health-probe-passthrough
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.
+115
−0
Open
fix(catalog): accept the web catalog's health_probe so the next sync passes the strict-decode test #281
Changes from all commits
Commits
Show all changes
3 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 |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package catalog | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
| "testing/fstest" | ||
| ) | ||
|
|
||
| // TestHealthProbeMarshalsToJSON. yaml.v3 decodes a nested mapping with an unquoted | ||
| // numeric key into map[any]any, which encoding/json refuses; the service list then | ||
| // cannot reach the UI and the app shows nothing. | ||
| func TestHealthProbeMarshalsToJSON(t *testing.T) { | ||
| fsys := fstest.MapFS{"services/x/a.yml": {Data: []byte(` | ||
| name: A | ||
| slug: a | ||
| docker: | ||
| image: a:1 | ||
| health_probe: | ||
| command: [myst, status] | ||
| checks: | ||
| - expect: | ||
| 200: ok | ||
| state: {1: up} | ||
| `)}} | ||
| cat, err := LoadEmbedded(fsys) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| svc := mustGet(t, cat, "a") | ||
| out, err := json.Marshal(svc) | ||
| if err != nil { | ||
| t.Fatalf("service with a numeric-keyed health_probe must marshal to JSON: %v", err) | ||
| } | ||
| var back struct { | ||
| Docker struct { | ||
| HealthProbe map[string]any `json:"healthProbe"` | ||
| } `json:"docker"` | ||
| } | ||
| if err := json.Unmarshal(out, &back); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| expect := back.Docker.HealthProbe["checks"].([]any)[0].(map[string]any)["expect"].(map[string]any) | ||
| if expect["200"] != "ok" || expect["state"].(map[string]any)["1"] != "up" { | ||
| t.Errorf("probe keys lost on the way through: %v", expect) | ||
| } | ||
| } | ||
|
|
||
| // TestHealthProbeNonFiniteFloatMarshals. YAML .nan, .inf and -.inf decode to | ||
| // float64 NaN and Inf, which encoding/json refuses just like map[any]any. | ||
| func TestHealthProbeNonFiniteFloatMarshals(t *testing.T) { | ||
| fsys := fstest.MapFS{"services/x/a.yml": {Data: []byte(` | ||
| name: A | ||
| slug: a | ||
| docker: | ||
| image: a:1 | ||
| health_probe: | ||
| threshold: .nan | ||
| checks: | ||
| - {max: .inf, min: -.inf, ok: 1.5} | ||
| `)}} | ||
| cat, err := LoadEmbedded(fsys) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if _, err := json.Marshal(cat.ListVisible()); err != nil { | ||
| t.Fatalf("service list with a non-finite health_probe float must marshal to JSON: %v", err) | ||
| } | ||
| p := mustGet(t, cat, "a").Docker.HealthProbe | ||
| c := p["checks"].([]any)[0].(map[string]any) | ||
| if p["threshold"] != "NaN" || c["max"] != "+Inf" || c["min"] != "-Inf" || c["ok"] != 1.5 { | ||
| t.Errorf("probe floats not normalised as expected: %v", p) | ||
| } | ||
| } |
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.