From 20befcf6d6ba75b8de40e9fb5b6f74affb94a805 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Thu, 30 Nov 2017 11:17:35 -0600 Subject: [PATCH] add 2 helper methods for building KVPair(s) --- types/kvpair.go | 19 +++++++++++++++++++ types/kvpair_test.go | 15 +++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 types/kvpair.go create mode 100644 types/kvpair_test.go diff --git a/types/kvpair.go b/types/kvpair.go new file mode 100644 index 00000000..c7aad440 --- /dev/null +++ b/types/kvpair.go @@ -0,0 +1,19 @@ +package types + +// KVPairInt is a helper method to build KV pair with an integer value. +func KVPairInt(key string, val int64) *KVPair { + return &KVPair{ + Key: key, + ValueInt: val, + ValueType: KVPair_INT, + } +} + +// KVPairString is a helper method to build KV pair with a string value. +func KVPairString(key, val string) *KVPair { + return &KVPair{ + Key: key, + ValueString: val, + ValueType: KVPair_STRING, + } +} diff --git a/types/kvpair_test.go b/types/kvpair_test.go new file mode 100644 index 00000000..d006d56b --- /dev/null +++ b/types/kvpair_test.go @@ -0,0 +1,15 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestKVPairInt(t *testing.T) { + assert.Equal(t, KVPairInt("a", 1), &KVPair{Key: "a", ValueType: KVPair_INT, ValueInt: 1}) +} + +func TestKVPairString(t *testing.T) { + assert.Equal(t, KVPairString("a", "b"), &KVPair{Key: "a", ValueType: KVPair_STRING, ValueString: "b"}) +}