Skip to content

Commit

Permalink
Merge pull request #76 from stripe/brandur-hedge-zero-value
Browse files Browse the repository at this point in the history
Hedge against the "zero Value"
  • Loading branch information
brandur-stripe authored May 30, 2018
2 parents ad06541 + 1dbc312 commit 56c5482
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion generator/datareplacer/datareplacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,18 @@ func ReplaceData(requestData map[string]interface{}, responseData map[string]int
}

func isSameType(v1, v2 interface{}) bool {
return reflect.ValueOf(v1).Type() == reflect.ValueOf(v2).Type()
v1Value := reflect.ValueOf(v1)
v2Value := reflect.ValueOf(v2)

// Reflect in Go has the concept of a "zero Value" (not be confused with a
// type's zero value with a lowercase "v") and asking for Type on one will
// panic. I'm not exactly sure under what conditions these are generated,
// but they are occasionally, so here we hedge against them.
//
// https://github.com/stripe/stripe-mock/issues/75
if !v1Value.IsValid() || !v2Value.IsValid() {
return false
}

return v1Value.Type() == v2Value.Type()
}

0 comments on commit 56c5482

Please sign in to comment.