Skip to content

Commit e8593fc

Browse files
authoredDec 27, 2024··
fix: single query param not included (#220)
1 parent 61498a4 commit e8593fc

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed
 

Diff for: ‎client_test.go

+39-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ func TestServiceCreateErrorsRetries(t *testing.T) {
198198
}
199199
}
200200

201-
// Tests
202201
func TestFmtQuery(t *testing.T) {
203202
t.Parallel()
204203

@@ -261,3 +260,42 @@ func TestFmtQuery(t *testing.T) {
261260
})
262261
}
263262
}
263+
264+
func TestServiceIntegrationEndpointGet(t *testing.T) {
265+
var callCount int64
266+
267+
// Creates a test server
268+
mux := http.NewServeMux()
269+
mux.HandleFunc(
270+
"/v1/project/{project}/integration_endpoint/{integration_endpoint_id}",
271+
func(w http.ResponseWriter, r *http.Request) {
272+
assert.Regexp(t, `go-client-codegen/[0-9\.]+ unit-test`, r.Header["User-Agent"])
273+
assert.Equal(t, r.RequestURI, "/v1/project/aiven-endpoint-project/integration_endpoint/foo?include_secrets=true&limit=999")
274+
275+
// Creates response
276+
w.Header().Set("Content-Type", "application/json")
277+
w.WriteHeader(http.StatusOK)
278+
_, err := w.Write([]byte(`{"service_integration_endpoint": {"endpoint_name": "wow"}}`))
279+
require.NoError(t, err)
280+
atomic.AddInt64(&callCount, 1)
281+
},
282+
)
283+
284+
server := httptest.NewServer(mux)
285+
defer server.Close()
286+
287+
// Points a new client to the server url
288+
c, err := NewClient(TokenOpt("token"), HostOpt(server.URL), UserAgentOpt("unit-test"))
289+
require.NotNil(t, c)
290+
require.NoError(t, err)
291+
292+
ctx := context.Background()
293+
project := "aiven-endpoint-project"
294+
out, err := c.ServiceIntegrationEndpointGet(ctx, project, "foo", service.ServiceIntegrationEndpointGetIncludeSecrets(true))
295+
require.NoError(t, err)
296+
require.NotNil(t, out)
297+
assert.Equal(t, "wow", out.EndpointName)
298+
299+
// All calls are received
300+
assert.EqualValues(t, 1, callCount)
301+
}

Diff for: ‎generator/main.go

+2-11
Original file line numberDiff line numberDiff line change
@@ -372,17 +372,8 @@ func exec() error {
372372
var block []jen.Code
373373

374374
// Adds unpacking for query params
375-
if len(queryParams) > 1 {
376-
q := jen.Id(queryParamName)
377-
p := jen.Id("p")
378-
v := jen.Id("v")
379-
callOpts = append(callOpts, p.Clone().Op("..."))
380-
block = append(
381-
block,
382-
p.Clone().Op(":=").Make(jen.Index().Index(jen.Lit(queryParamArraySize)).String(), jen.Lit(0), jen.Len(q)),
383-
jen.For(jen.List(jen.Id("_"), v.Clone().Op(":=").Range().Add(jen.Id(queryParamName)))).
384-
Block(p.Clone().Op("=").Append(p, v)),
385-
)
375+
if len(queryParams) > 0 {
376+
callOpts = append(callOpts, jen.Id(queryParamName).Op("..."))
386377
}
387378

388379
// Implementation (method's) body

Diff for: ‎handler/clickhouse/clickhouse.go

+1-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎handler/kafka/kafka.go

+2-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎handler/service/service.go

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.