Skip to content

Commit

Permalink
Persist correct handler names in schema fields
Browse files Browse the repository at this point in the history
We were mutating the handler name in a copy of the schema field rather
than in the actual underlying field that gets returned.
  • Loading branch information
rohansingh committed May 15, 2024
1 parent 1d1639c commit 5db707e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
4 changes: 3 additions & 1 deletion schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ func FromStarlark(
return nil, err
}

for i, schemaField := range schema.Fields {
for i := range schema.Fields {
schemaField := &schema.Fields[i]

var handlerFun *starlark.Function
if schemaField.StarlarkHandler != nil {
handlerFun = schemaField.StarlarkHandler
Expand Down
16 changes: 8 additions & 8 deletions schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def main():
ID: "locationbasedid",
Name: "Locationbased",
Description: "A Locationbased",
Handler: "locationbasedhandler",
Handler: "locationbasedid$locationbasedhandler",
Icon: "locationDot",
},
{
Expand Down Expand Up @@ -258,15 +258,15 @@ def main():
ID: "typeaheadid",
Name: "Typeahead",
Description: "A Typeahead",
Handler: "typeaheadhandler",
Handler: "typeaheadid$typeaheadhandler",
Icon: "train",
},
{
Type: "oauth2",
ID: "oauth2id",
Name: "OAuth2",
Description: "Authentication",
Handler: "oauth2handler",
Handler: "oauth2id$oauth2handler",
Icon: "train",
ClientID: "oauth2_clientid",
AuthorizationEndpoint: "https://example.com/auth",
Expand Down Expand Up @@ -498,7 +498,7 @@ def main():
ID: "locationbasedid",
Name: "Locationbased",
Description: "A Locationbased",
Handler: "locationbasedhandler",
Handler: "locationbasedid$locationbasedhandler",
Icon: "locationDot",
},
{
Expand Down Expand Up @@ -578,23 +578,23 @@ def main():
{
Type: "generated",
ID: "generatedid",
Handler: "generatedhandler",
Handler: "generatedid$generatedhandler",
Source: "radioid",
},
{
Type: "typeahead",
ID: "typeaheadid",
Name: "Typeahead",
Description: "A Typeahead",
Handler: "typeaheadhandler",
Handler: "typeaheadid$typeaheadhandler",
Icon: "train",
},
{
Type: "oauth2",
ID: "oauth2id",
Name: "OAuth2",
Description: "Authentication",
Handler: "oauth2handler",
Handler: "oauth2id$oauth2handler",
Icon: "train",
ClientID: "oauth2_clientid",
AuthorizationEndpoint: "https://example.com/auth",
Expand Down Expand Up @@ -1143,7 +1143,7 @@ def main():
assert.Equal(t, "1", s.Version)
assert.Equal(t, 1, len(s.Fields))
assert.Equal(t, "locationbased", s.Fields[0].Type)
assert.Equal(t, "get_stations", s.Fields[0].Handler)
assert.Equal(t, "station$get_stations", s.Fields[0].Handler)

data, err = app.CallSchemaHandler(context.Background(), "get_stations", "locationdata")
var options []schema.SchemaOption
Expand Down

0 comments on commit 5db707e

Please sign in to comment.