blob: 2f3818d6b16033803f9a48b694a5ab5d7353e1cf [file] [log] [blame]
khenaidoocfee5f42018-07-19 22:47:38 -04001package kvstore
2
3import (
khenaidoocfee5f42018-07-19 22:47:38 -04004 "github.com/stretchr/testify/assert"
khenaidoo5c11af72018-07-20 17:21:05 -04005 "testing"
6 "time"
khenaidoocfee5f42018-07-19 22:47:38 -04007)
8
9func TestDurationWithNegativeTimeout(t *testing.T) {
10 actualResult := GetDuration(-1)
11 var expectedResult = defaultKVGetTimeout * time.Second
12
13 assert.Equal(t, expectedResult, actualResult)
14}
15
16func TestDurationWithZeroTimeout(t *testing.T) {
17 actualResult := GetDuration(0)
18 var expectedResult = defaultKVGetTimeout * time.Second
19
20 assert.Equal(t, expectedResult, actualResult)
21}
22
23func TestDurationWithTimeout(t *testing.T) {
24 actualResult := GetDuration(10)
25 var expectedResult = time.Duration(10) * time.Second
26
27 assert.Equal(t, expectedResult, actualResult)
28}
29
30func TestToStringWithString(t *testing.T) {
31 actualResult, _ := ToString("myString")
32 var expectedResult = "myString"
33
34 assert.Equal(t, expectedResult, actualResult)
35}
36
37func TestToStringWithEmpty(t *testing.T) {
38 actualResult, _ := ToString("")
39 var expectedResult = ""
40
41 assert.Equal(t, expectedResult, actualResult)
42}
43
44func TestToStringWithByte(t *testing.T) {
45 mByte := []byte("Hello")
46 actualResult, _ := ToString(mByte)
47 var expectedResult = "Hello"
48
49 assert.Equal(t, expectedResult, actualResult)
50}
51
52func TestToStringWithEmptyByte(t *testing.T) {
53 mByte := []byte("")
54 actualResult, _ := ToString(mByte)
55 var expectedResult = ""
56
57 assert.Equal(t, expectedResult, actualResult)
58}
59
60func TestToStringForErrorCase(t *testing.T) {
61 mInt := 200
62 actualResult, error := ToString(mInt)
63 var expectedResult = ""
64
65 assert.Equal(t, expectedResult, actualResult)
66 assert.NotEqual(t, error, nil)
67}