Created
March 8, 2018 08:35
-
-
Save simcap/42581349520e505fb5112565aa206e09 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package client_test | |
| import ( | |
| "bytes" | |
| "encoding/json" | |
| "strings" | |
| "testing" | |
| "github.com/wallix/gopeps/pepssdk/go/client" | |
| ) | |
| type payload struct { | |
| One string `base64:""` | |
| Two string | |
| N *nested | |
| } | |
| type nested struct { | |
| One string | |
| Two []byte `base64:""` | |
| Three []byte `base64:""` | |
| } | |
| func TestDecodeBase64Fields(t *testing.T) { | |
| j := `{ | |
| "One": "b25l", | |
| "Two": "not encoded", | |
| "N": { | |
| "One": "not encoded", | |
| "Two": "ZW1iZWRkZWRfdHdv" | |
| } | |
| }` | |
| var p payload | |
| json.NewDecoder(strings.NewReader(j)).Decode(&p) | |
| client.DecodeBase64Payload(&p) | |
| if got, want := p.One, "one"; got != want { | |
| t.Fatalf("got %s, want %s", got, want) | |
| } | |
| if got, want := p.Two, "not encoded"; got != want { | |
| t.Fatalf("got %s, want %s", got, want) | |
| } | |
| if got, want := p.N.One, "not encoded"; got != want { | |
| t.Fatalf("nested: got %s, want %s", got, want) | |
| } | |
| if got, want := p.N.Two, []byte("embedded_two"); !bytes.Equal(got, want) { | |
| t.Fatalf("nested: got %v, want %v", got, want) | |
| } | |
| if got, want := p.N.Three, []byte(nil); !bytes.Equal(got, want) { | |
| t.Fatalf("nested: got %v, want %v", got, want) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment