Skip to content

Commit

Permalink
fix: single query param not included (#220)
Browse files Browse the repository at this point in the history
byashimov authored Dec 27, 2024
1 parent 61498a4 commit e8593fc
Showing 5 changed files with 47 additions and 30 deletions.
40 changes: 39 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
@@ -198,7 +198,6 @@ func TestServiceCreateErrorsRetries(t *testing.T) {
}
}

// Tests
func TestFmtQuery(t *testing.T) {
t.Parallel()

@@ -261,3 +260,42 @@ func TestFmtQuery(t *testing.T) {
})
}
}

func TestServiceIntegrationEndpointGet(t *testing.T) {
var callCount int64

// Creates a test server
mux := http.NewServeMux()
mux.HandleFunc(
"/v1/project/{project}/integration_endpoint/{integration_endpoint_id}",
func(w http.ResponseWriter, r *http.Request) {
assert.Regexp(t, `go-client-codegen/[0-9\.]+ unit-test`, r.Header["User-Agent"])
assert.Equal(t, r.RequestURI, "/v1/project/aiven-endpoint-project/integration_endpoint/foo?include_secrets=true&limit=999")

// Creates response
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, err := w.Write([]byte(`{"service_integration_endpoint": {"endpoint_name": "wow"}}`))
require.NoError(t, err)
atomic.AddInt64(&callCount, 1)
},
)

server := httptest.NewServer(mux)
defer server.Close()

// Points a new client to the server url
c, err := NewClient(TokenOpt("token"), HostOpt(server.URL), UserAgentOpt("unit-test"))
require.NotNil(t, c)
require.NoError(t, err)

ctx := context.Background()
project := "aiven-endpoint-project"
out, err := c.ServiceIntegrationEndpointGet(ctx, project, "foo", service.ServiceIntegrationEndpointGetIncludeSecrets(true))
require.NoError(t, err)
require.NotNil(t, out)
assert.Equal(t, "wow", out.EndpointName)

// All calls are received
assert.EqualValues(t, 1, callCount)
}
13 changes: 2 additions & 11 deletions generator/main.go
Original file line number Diff line number Diff line change
@@ -372,17 +372,8 @@ func exec() error {
var block []jen.Code

// Adds unpacking for query params
if len(queryParams) > 1 {
q := jen.Id(queryParamName)
p := jen.Id("p")
v := jen.Id("v")
callOpts = append(callOpts, p.Clone().Op("..."))
block = append(
block,
p.Clone().Op(":=").Make(jen.Index().Index(jen.Lit(queryParamArraySize)).String(), jen.Lit(0), jen.Len(q)),
jen.For(jen.List(jen.Id("_"), v.Clone().Op(":=").Range().Add(jen.Id(queryParamName)))).
Block(p.Clone().Op("=").Append(p, v)),
)
if len(queryParams) > 0 {
callOpts = append(callOpts, jen.Id(queryParamName).Op("..."))
}

// Implementation (method's) body
6 changes: 1 addition & 5 deletions handler/clickhouse/clickhouse.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 2 additions & 10 deletions handler/kafka/kafka.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions handler/service/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e8593fc

Please sign in to comment.