Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(go-sdk): allow empty string for ulid #145

Merged
merged 2 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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