Skip to content
Snippets Groups Projects
Unverified Commit 2dcfd037 authored by Silas Davis's avatar Silas Davis
Browse files

Fix mapAndValues and even write some, like, test

parent 5de1ed64
No related branches found
No related tags found
No related merge requests found
......@@ -141,6 +141,7 @@ func performCall(client rpcclient.Client, method string,
return
}
func mapAndValues(orderedKeyVals ...interface{}) (map[string]interface{},
[]interface{}, error) {
if len(orderedKeyVals)%2 != 0 {
......@@ -158,7 +159,7 @@ func mapAndValues(orderedKeyVals ...interface{}) (map[string]interface{},
}
val := orderedKeyVals[i+1]
paramsMap[key] = val
paramsSlice = append(paramsSlice, val)
paramsSlice[i/2] = val
}
return paramsMap, paramsSlice, nil
}
......
package client
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMapsAndValues(t *testing.T) {
type aStruct struct {
Baz int
}
dict, vals, err := mapAndValues("Foo", aStruct{5},
"Bar", "Nibbles")
assert.Equal(t, map[string]interface{}{
"Foo": aStruct{5},
"Bar": "Nibbles",
}, dict)
assert.Equal(t, []interface{}{aStruct{5}, "Nibbles"}, vals)
// Empty map
dict, vals, err = mapAndValues()
assert.Equal(t, map[string]interface{}{}, dict)
assert.Equal(t, []interface{}{}, vals)
assert.NoError(t, err, "Empty mapsAndValues call should be fine")
// Invalid maps
assert.NoError(t, err, "Empty mapsAndValues call should be fine")
_, _, err = mapAndValues("Foo", 4, "Bar")
assert.Error(t, err, "Should be an error to get an odd number of arguments")
_, _, err = mapAndValues("Foo", 4, 4, "Bar")
assert.Error(t, err, "Should be an error to provide non-string keys")
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment