Skip to content

Commit

Permalink
fix(go-sdk): allow empty string for ulid
Browse files Browse the repository at this point in the history
  • Loading branch information
adriantam committed Jun 27, 2023
1 parent 3fd9111 commit 709130d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/clients/go/template/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (a *{{{classname}}}Service) {{nickname}}Execute(r {{#structPrefix}}{{&class
if a.client.cfg.StoreId == "" {
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("Configuration.StoreId is required and must be specified to call this method")
}
if !internalutils.IsWellFormedUlidString(a.client.cfg.StoreId) {
if a.client.cfg.StoreId != "" && !internalutils.IsWellFormedUlidString(a.client.cfg.StoreId) {
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("Configuration.StoreId is invalid")
}
{{/pathParams.0}}
Expand Down
2 changes: 1 addition & 1 deletion config/clients/go/template/client/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewSdkClient(cfg *ClientConfiguration) (*{{appShortName}}Client, error) {

// store id is already validate as part of configuration validation

if cfg.AuthorizationModelId != nil && !internalutils.IsWellFormedUlidString(*cfg.AuthorizationModelId) {
if cfg.AuthorizationModelId != nil && *cfg.AuthorizationModelId != "" && !internalutils.IsWellFormedUlidString(*cfg.AuthorizationModelId) {
return nil, FgaInvalidError{param: "AuthorizationModelId", description: "ULID"}
}

Expand Down
22 changes: 22 additions & 0 deletions config/clients/go/template/client/client_test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ func Test{{appShortName}}Client(t *testing.T) {
}
})

t.Run("Allow client to have empty store ID specified", func(t *testing.T){
_, err := NewSdkClient(&ClientConfiguration{
ApiHost: "api.fga.example",
StoreId: "",
})
if err != nil {
t.Fatalf("Expect no error when store id is empty but has %v", err)
}
})

t.Run("Validate store ID when specified", func(t *testing.T){
_, err := NewSdkClient(&ClientConfiguration{
ApiHost: "api.fga.example",
Expand All @@ -60,6 +70,18 @@ func Test{{appShortName}}Client(t *testing.T) {
}
})

t.Run("Allow auth model ID to be empty when specified", func(t *testing.T){
_, err := NewSdkClient(&ClientConfiguration{
ApiHost: "api.fga.example",
StoreId: "01GXSB9YR785C4FYS3C0RTG7B2",
AuthorizationModelId: {{packageName}}.PtrString(""),
})
if err != nil {
t.Fatalf("Expect no error when auth model id is empty but has %v", err)
}
})


/* Stores */
t.Run("ListStores", func(t *testing.T) {
test := TestDefinition{
Expand Down

0 comments on commit 709130d

Please sign in to comment.