Browse Source

add 2 helper methods for building KVPair(s)

pull/1780/head
Anton Kaliaev 7 years ago
parent
commit
20befcf6d6
No known key found for this signature in database GPG Key ID: 7B6881D965918214
2 changed files with 34 additions and 0 deletions
  1. +19
    -0
      types/kvpair.go
  2. +15
    -0
      types/kvpair_test.go

+ 19
- 0
types/kvpair.go View File

@ -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,
}
}

+ 15
- 0
types/kvpair_test.go View File

@ -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"})
}

Loading…
Cancel
Save