Skip to content

Commit

Permalink
fix(go-sdk): correctly set consistency on batch check
Browse files Browse the repository at this point in the history
  • Loading branch information
ewanharris committed Oct 9, 2024
1 parent baa512b commit b7ba0e6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
14 changes: 10 additions & 4 deletions config/clients/go/template/client/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2012,17 +2012,23 @@ func (client *{{appShortName}}Client) BatchCheckExecute(request SdkClientBatchCh
return nil, err
}

checkOptions := &ClientCheckOptions{
AuthorizationModelId: authorizationModelId,
StoreId: storeId,
}

if request.GetOptions() != nil && request.GetOptions().Consistency != nil {
checkOptions.Consistency = request.GetOptions().Consistency
}

for index, checkBody := range *request.GetBody() {
index, checkBody := index, checkBody
group.Go(func() error {
singleResponse, err := client.CheckExecute(&SdkClientCheckRequest{
ctx: ctx,
Client: client,
body: &checkBody,
options: &ClientCheckOptions{
AuthorizationModelId: authorizationModelId,
StoreId: storeId,
},
options: checkOptions,
})

if _, ok := err.(fgaSdk.FgaApiAuthenticationError); ok {
Expand Down
12 changes: 9 additions & 3 deletions config/clients/go/template/client/client_test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ func Test{{appShortName}}Client(t *testing.T) {
options := ClientBatchCheckOptions{
AuthorizationModelId: {{packageName}}.PtrString(authModelId),
MaxParallelRequests: {{packageName}}.PtrInt32(5),
Consistency: {{packageName}}.CONSISTENCYPREFERENCE_UNSPECIFIED.Ptr(),
Consistency: {{packageName}}.CONSISTENCYPREFERENCE_HIGHER_CONSISTENCY.Ptr(),
}

var expectedResponse {{packageName}}.CheckResponse
Expand All @@ -2202,7 +2202,7 @@ func Test{{appShortName}}Client(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterMatcherResponder(test.Method, fmt.Sprintf("%s/stores/%s/%s", fgaClient.GetConfig().ApiUrl, getStoreId(t, fgaClient), test.RequestPath),
httpmock.BodyContainsString(`"consistency":"UNSPECIFIED"`),
httpmock.BodyContainsString(`"consistency":"HIGHER_CONSISTENCY"`),
func(req *http.Request) (*http.Response, error) {
resp, err := httpmock.NewJsonResponse(test.ResponseStatus, expectedResponse)
if err != nil {
Expand All @@ -2212,10 +2212,16 @@ func Test{{appShortName}}Client(t *testing.T) {
},
)

_, err := fgaClient.BatchCheck(context.Background()).Body(requestBody).Options(options).Execute()
checks, err := fgaClient.BatchCheck(context.Background()).Body(requestBody).Options(options).Execute()
if err != nil {
t.Fatalf("%v", err)
}

for _, check := range *checks {
if check.Error != nil {
t.Fatalf("a check failed %v", check.Error)
}
}
})

t.Run("Expand", func(t *testing.T) {
Expand Down

0 comments on commit b7ba0e6

Please sign in to comment.