jmsperu opened a new pull request, #153: URL: https://github.com/apache/cloudstack-go/pull/153
Fixes #87. ### Problem `GetTemplateByName` resolves the template id *with* the `zoneid` constraint (via `GetTemplateID`), but then calls `GetTemplateByID` **without** it: ```go id, count, err := s.GetTemplateID(name, templatefilter, zoneid, opts...) ... r, count, err := s.GetTemplateByID(id, templatefilter, opts...) // zone dropped ``` A template registered in multiple zones lists one row per zone for the same UUID, so the by-id lookup returns `count > 1` and the helper fails: ``` There is more then one result for Template UUID: 06145677-058a-456a-89a0-af4afd6fffcf! ``` `GetIsoByName` has the identical issue. ### Fix These helpers are generated, so the fix is in the generator (`generate/generate.go`): for `Template`/`Iso`, pass the zone into the by-ID lookup using the existing `WithZone` option, then apply it to the two generated helpers: ```go r, count, err := s.GetTemplateByID(id, templatefilter, append(opts, WithZone(zoneid))...) ``` `WithZone` is a no-op when `zoneid` is empty and sets the id directly when given a UUID (no extra lookup), so this is safe and adds no API calls. ### Test Adds `test/GetTemplateByNameZoneRegression_test.go`: the mock returns two rows for the unscoped by-id lookup and one when `zoneid` is present. It **fails with the exact `There is more then one result` error on current `main`** and passes with the fix. ### Verification - `go build ./...` — clean - `go test ./test/ -run TestGetTemplateByNameScopesByIDLookupToZone` — passes (and fails with the #87 error when the fix is reverted) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
