-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Made logger an explicit dependency of Adyen. - Implemented signature todos. - Removed unused Java-like getter and setter methods. - Moved test helpers into a TestMain function. - Simplified bool parsing into boolean.go with tests in boolean_test.go - Removed newEnvironment helper and replaced with simple initialisation. - Added tests for URL formatting. - Simplified some bool checks in tests. - Added a todo section in README. - Replaced HTTP verb magic strings with stdlib constants.
- Loading branch information
1 parent
6c1e820
commit d8d302b
Showing
17 changed files
with
288 additions
and
261 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package adyen | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// stringBool allows us to unmarhsal Adyen Boolean values | ||
// which appear as strings instead of bools. | ||
type stringBool bool | ||
|
||
func (b *stringBool) UnmarshalJSON(data []byte) (err error) { | ||
str := strings.TrimFunc(strings.ToLower(string(data)), func(c rune) bool { | ||
return c == ' ' || c == '"' | ||
}) | ||
|
||
parsed, err := strconv.ParseBool(str) | ||
if err != nil { | ||
return | ||
} | ||
|
||
*b = stringBool(parsed) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package adyen | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
) | ||
|
||
type thing struct { | ||
Bool stringBool `json:"value"` | ||
} | ||
|
||
func TestStringBool_Unmarshal(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
json string | ||
exp bool | ||
expErr bool | ||
}{ | ||
{ | ||
name: "empty", | ||
json: `{ "value": "" }`, | ||
exp: false, | ||
expErr: true, | ||
}, | ||
{ | ||
name: "true", | ||
json: `{ "value": "true" }`, | ||
exp: true, | ||
}, | ||
{ | ||
name: "TRUE", | ||
json: `{ "value": "TRUE" }`, | ||
exp: true, | ||
}, | ||
{ | ||
name: "1", | ||
json: `{ "value": "1" }`, | ||
exp: true, | ||
}, | ||
{ | ||
name: "spaces", | ||
json: `{ "value": " true " }`, | ||
exp: true, | ||
}, | ||
{ | ||
name: "false", | ||
json: `{ "value": "false" }`, | ||
exp: false, | ||
}, | ||
{ | ||
name: "FALSE", | ||
json: `{ "value": "FALSE" }`, | ||
exp: false, | ||
}, | ||
{ | ||
name: "0", | ||
json: `{ "value": "0" }`, | ||
exp: false, | ||
}, | ||
{ | ||
name: "spaces", | ||
json: `{ "value": " false " }`, | ||
exp: false, | ||
}, | ||
{ | ||
name: "spaces", | ||
json: `{ "value": " false " }`, | ||
exp: false, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.name, func(t *testing.T) { | ||
var th thing | ||
err := json.Unmarshal([]byte(c.json), &th) | ||
if !c.expErr && err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
if c.expErr && err == nil { | ||
t.Fatalf("expected error but didn't get one") | ||
} | ||
|
||
if stringBool(c.exp) != th.Bool { | ||
t.Fatalf("my exp: %v but got %v", c.exp, th.Bool) | ||
} | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.