prysm-pulse/validator/keymanager/v1/opts_test.go

78 lines
1.5 KiB
Go
Raw Normal View History

Begin Scaffold of Validator Accounts V2 (#6310) * v2 refactor * fix up imports * builds * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge branch 'master' into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * imports keymanager v1 * Update validator/keymanager/v1/remote.go * Update validator/client/polling/propose.go * Update validator/keymanager/v1/wallet.go * fmt * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * Merge refs/heads/master into accounts-revamp-p1 * fix conf * fix build * gaz
2020-06-27 15:48:36 +00:00
package v1
import (
"bytes"
"encoding/json"
"errors"
"testing"
)
func TestDecodeOpts(t *testing.T) {
tests := []struct {
name string
input string
res interface{}
err error
result string
}{
{
name: "EmptyInput",
input: "",
res: &struct {
Name string `json:"name,omitempty"`
}{},
result: `{}`,
},
{
name: "EmptyJSON",
input: "{}",
res: &struct {
Name string `json:"name,omitempty"`
}{},
result: `{}`,
},
{
name: "BadInput",
input: "bad",
res: &struct {
Name string `json:"name,omitempty"`
}{},
err: errors.New("open bad: no such file or directory"),
},
{
name: "GoodDirect",
input: `{"name":"test"}`,
res: &struct {
Name string `json:"name,omitempty"`
}{},
result: `{"name":"test"}`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
err := decodeOpts(test.input, test.res)
if test.err == nil {
if err != nil {
t.Fatalf("Unexepcted error: %v", err)
}
recoded, err := json.Marshal(test.res)
if err != nil {
t.Fatalf("Unexepcted error encoding result: %v", err)
}
if !bytes.Equal([]byte(test.result), recoded) {
t.Fatalf("Unexpected recoded value: expected %s, received %s", test.result, string(recoded))
}
} else {
if err == nil {
t.Fatalf("Missing expected error: %v", test.err)
}
if test.err.Error() != err.Error() {
t.Fatalf("Unexpected error value: expected %v, received %v", test.err.Error(), err.Error())
}
}
})
}
}