github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/rpc/rpcinfo/infoclient/client_test.go (about)

     1  package infoclient
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestParamsMap(t *testing.T) {
    10  	type aStruct struct {
    11  		Baz int
    12  	}
    13  	dict, err := ParamsToMap("Foo", aStruct{5},
    14  		"Bar", "Nibbles")
    15  	assert.NoError(t, err, "Should not be a paramsMaperror")
    16  	assert.Equal(t, map[string]interface{}{
    17  		"Foo": aStruct{5},
    18  		"Bar": "Nibbles",
    19  	}, dict)
    20  
    21  	// Empty map
    22  	dict, err = ParamsToMap()
    23  	assert.Equal(t, map[string]interface{}{}, dict)
    24  	assert.NoError(t, err, "Empty mapsAndValues call should be fine")
    25  
    26  	// Invalid maps
    27  	assert.NoError(t, err, "Empty mapsAndValues call should be fine")
    28  	_, err = ParamsToMap("Foo", 4, "Bar")
    29  	assert.Error(t, err, "Should be an error to get an odd number of arguments")
    30  
    31  	_, err = ParamsToMap("Foo", 4, 4, "Bar")
    32  	assert.Error(t, err, "Should be an error to provide non-string keys")
    33  }