Skip to content

Commit

Permalink
Merge pull request #153 from niclic/fixup-params
Browse files Browse the repository at this point in the history
Check RuntimeParameter value before creating FederationUpstream.
  • Loading branch information
michaelklishin authored May 13, 2020
2 parents 16696c2 + c66af44 commit 9f8e3d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 5 additions & 1 deletion federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ func paramToUpstream(p *RuntimeParameter) (up *FederationUpstream) {
Component: p.Component,
}

m, ok := p.Value.(map[string]interface{})
if !ok {
return up
}

def := FederationDefinition{}
m := p.Value.(map[string]interface{})

if v, ok := m["uri"].(string); ok {
def.Uri = v
Expand Down
13 changes: 13 additions & 0 deletions rabbithole_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2270,4 +2270,17 @@ var _ = Describe("Rabbithole", func() {
})
})
})

Context("paramToUpstream", func() {
Context("when the parameter value is not initialized", func() {
It("returns an empty FederationUpstream", func() {
p := RuntimeParameter{} // p.Value is interface{}
up := paramToUpstream(&p)
Ω(up.Name).Should(BeEmpty())
Ω(up.Vhost).Should(BeEmpty())
Ω(up.Component).Should(BeEmpty())
Ω(up.Definition).Should(Equal(FederationDefinition{}))
})
})
})
})
8 changes: 4 additions & 4 deletions runtime_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ func (c *Client) GetRuntimeParameter(component, vhost, name string) (p *RuntimeP
// PutRuntimeParameter creates or updates a runtime parameter.
func (c *Client) PutRuntimeParameter(component, vhost, name string, value interface{}) (res *http.Response, err error) {
p := RuntimeParameter{
name,
vhost,
component,
value,
Name: name,
Vhost: vhost,
Component: component,
Value: value,
}

body, err := json.Marshal(p)
Expand Down

0 comments on commit 9f8e3d8

Please sign in to comment.