Skip to content

Commit

Permalink
add integration tests to go server
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmossas committed Nov 22, 2024
1 parent 2af96d9 commit e3f44d1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
21 changes: 13 additions & 8 deletions languages/go/go-server/decode_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,14 +605,19 @@ func structFromJSON(data *gjson.Result, target reflect.Value, c *ValidationConte
if !fieldMeta.IsExported() {
continue
}
switch c.KeyCasing {
case KeyCasingCamelCase:
fieldName = strcase.ToLowerCamel(fieldName)
case KeyCasingPascalCase:
case KeyCasingSnakeCase:
fieldName = strcase.ToSnake(fieldName)
default:
fieldName = strcase.ToLowerCamel(fieldName)
keyTag := fieldMeta.Tag.Get("key")
if len(keyTag) > 0 {
fieldName = keyTag
} else {
switch c.KeyCasing {
case KeyCasingCamelCase:
fieldName = strcase.ToLowerCamel(fieldName)
case KeyCasingPascalCase:
case KeyCasingSnakeCase:
fieldName = strcase.ToSnake(fieldName)
default:
fieldName = strcase.ToLowerCamel(fieldName)
}
}
jsonResult := data.Get(fieldName)
enumValues := None[[]string]()
Expand Down
26 changes: 26 additions & 0 deletions tests/servers/go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func main() {
arri.ScopedRpc(&app, "tests", SendError, arri.RpcOptions{})
arri.ScopedRpc(&app, "tests", SendObject, arri.RpcOptions{})
arri.ScopedRpc(&app, "tests", SendObjectWithNullableFields, arri.RpcOptions{})
arri.ScopedRpc(&app, "tests", SendObjectWithPascalCaseKeys, arri.RpcOptions{})
arri.ScopedRpc(&app, "tests", SendObjectWithSnakeCaseKeys, arri.RpcOptions{})
arri.ScopedRpc(&app, "tests", SendPartialObject, arri.RpcOptions{})
arri.ScopedRpc(&app, "tests", SendRecursiveObject, arri.RpcOptions{})
arri.ScopedRpc(&app, "tests", SendRecursiveUnion, arri.RpcOptions{})
Expand Down Expand Up @@ -236,6 +238,30 @@ func SendObjectWithNullableFields(params ObjectWithEveryNullableType, _ AppConte
return params, nil
}

type ObjectWithPascalCaseKeys struct {
CreatedAt time.Time `key:"CreatedAt"`
DisplayName string `key:"DisplayName"`
EmailAddress arri.Option[string] `key:"EmailAddress"`
PhoneNumber arri.Nullable[string] `key:"PhoneNumber"`
IsAdmin arri.Option[bool] `key:"IsAdmin"`
}

func SendObjectWithPascalCaseKeys(params ObjectWithPascalCaseKeys, _ AppContext) (ObjectWithPascalCaseKeys, arri.RpcError) {
return params, nil
}

type ObjectWithSnakeCaseKeys struct {
CreatedAt time.Time `key:"created_at"`
DisplayName string `key:"display_name"`
EmailAddress arri.Option[string] `key:"email_address"`
PhoneNumber arri.Nullable[string] `key:"phone_number"`
IsAdmin arri.Option[bool] `key:"is_admin"`
}

func SendObjectWithSnakeCaseKeys(params ObjectWithSnakeCaseKeys, _ AppContext) (ObjectWithSnakeCaseKeys, arri.RpcError) {
return params, nil
}

type ObjectWithEveryOptionalType struct {
Any arri.Option[any]
Boolean arri.Option[bool]
Expand Down

0 comments on commit e3f44d1

Please sign in to comment.