-
Notifications
You must be signed in to change notification settings - Fork 7
(fix): Bump control-plane for multi-resource catalog #32
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
Changes from all commits
5f5d685
ecb0549
3d850ed
3bf7d4c
ef5cf90
5d9c332
654d515
0ad2494
1fca8d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,48 @@ func sampleCatalogItemResponse() map[string]any { | |
| } | ||
| } | ||
|
|
||
| // sampleTwoResourceCatalogItemResponse returns a catalog item with two distinct resources. | ||
| func sampleTwoResourceCatalogItemResponse() map[string]any { | ||
| return map[string]any{ | ||
| "path": "catalog-items/my-catalog-item", | ||
| "uid": "b2c3d4e5-f6a7-8901-bcde-f12345678901", | ||
| "display_name": "App with Database", | ||
| "create_time": "2026-03-09T10:00:00Z", | ||
| "spec": map[string]any{ | ||
| "resources": []any{ | ||
| map[string]any{ | ||
| "name": "app", | ||
| "service_type": "container", | ||
| "fields": []any{ | ||
| map[string]any{ | ||
| "path": "image.reference", | ||
| "default": "nginx:latest", | ||
| }, | ||
| }, | ||
| }, | ||
| map[string]any{ | ||
| "name": "db", | ||
| "service_type": "database", | ||
| "requires_resources": []any{"app"}, | ||
| "fields": []any{ | ||
| map[string]any{ | ||
| "path": "engine", | ||
| "default": "postgres", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| // writeTempJSON marshals v to JSON and writes it to a temporary file. | ||
| func writeTempJSON(v any) string { | ||
| data, err := json.Marshal(v) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| return writeTempFile(string(data), ".json") | ||
| } | ||
|
|
||
| // emptyCatalogItemListResponse returns a standard empty catalog item list response body. | ||
| func emptyCatalogItemListResponse() map[string]any { | ||
| return map[string]any{ | ||
|
|
@@ -86,6 +128,15 @@ var _ = Describe("Catalog Item Commands", func() { | |
| var body map[string]any | ||
| Expect(json.NewDecoder(r.Body).Decode(&body)).To(Succeed()) | ||
| Expect(body["display_name"]).To(Equal("Small Container")) | ||
| spec, ok := body["spec"].(map[string]any) | ||
| Expect(ok).To(BeTrue(), "request body must include spec") | ||
| resources, ok := spec["resources"].([]any) | ||
|
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. This new test asserts exactly one resource, so a regression that drops additional resources or resource-specific values can still pass. Please add a two-resource case with distinct values.
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. +1
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. Updated the tests 0ad2494 |
||
| Expect(ok).To(BeTrue(), "request body must include spec.resources") | ||
|
qodo-code-review[bot] marked this conversation as resolved.
|
||
| Expect(resources).To(HaveLen(1)) | ||
| resource, ok := resources[0].(map[string]any) | ||
| Expect(ok).To(BeTrue()) | ||
| Expect(resource["name"]).To(Equal("main")) | ||
| Expect(resource["service_type"]).To(Equal("container")) | ||
|
|
||
| writeJSONResponse(w, http.StatusCreated, sampleCatalogItemResponse()) | ||
| })) | ||
|
|
@@ -140,6 +191,30 @@ var _ = Describe("Catalog Item Commands", func() { | |
| Expect(errors.As(err, &fmtErr)).To(BeTrue()) | ||
| Expect(errBuf.String()).To(ContainSubstring("INTERNAL")) | ||
| }) | ||
|
|
||
| It("should create a catalog item with multiple resources", func() { | ||
| expected := sampleTwoResourceCatalogItemResponse() | ||
|
|
||
| server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| Expect(r.Method).To(Equal(http.MethodPost)) | ||
| Expect(r.URL.Path).To(Equal("/api/v1alpha1/catalog-items")) | ||
|
|
||
| var body map[string]any | ||
| Expect(json.NewDecoder(r.Body).Decode(&body)).To(Succeed()) | ||
| Expect(body["display_name"]).To(Equal(expected["display_name"])) | ||
| Expect(body["spec"]).To(Equal(expected["spec"])) | ||
|
|
||
| writeJSONResponse(w, http.StatusCreated, expected) | ||
| })) | ||
|
|
||
| inputFile := writeTempJSON(map[string]any{ | ||
| "display_name": expected["display_name"], | ||
| "spec": expected["spec"], | ||
| }) | ||
|
|
||
| err := executeCommand("catalog", "item", "create", "--from-file", inputFile) | ||
| Expect(err).NotTo(HaveOccurred()) | ||
| }) | ||
| }) | ||
|
|
||
| Describe("list", func() { | ||
|
|
@@ -290,11 +365,9 @@ var _ = Describe("Catalog Item Commands", func() { | |
| out := outBuf.String() | ||
| Expect(out).To(ContainSubstring("UID")) | ||
| Expect(out).To(ContainSubstring("DISPLAY NAME")) | ||
| Expect(out).To(ContainSubstring("SERVICE TYPE")) | ||
| Expect(out).To(ContainSubstring("CREATED")) | ||
| Expect(out).To(ContainSubstring("b2c3d4e5-f6a7-8901-bcde-f12345678901")) | ||
| Expect(out).To(ContainSubstring("Small Container")) | ||
| Expect(out).To(ContainSubstring("container")) | ||
| Expect(out).To(ContainSubstring("2026-03-09T10:00:00Z")) | ||
| }) | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.