khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 1 | package kvstore |
| 2 | |
| 3 | import ( |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 4 | "github.com/stretchr/testify/assert" |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 5 | "testing" |
| 6 | "time" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 7 | ) |
| 8 | |
| 9 | func TestDurationWithNegativeTimeout(t *testing.T) { |
| 10 | actualResult := GetDuration(-1) |
| 11 | var expectedResult = defaultKVGetTimeout * time.Second |
| 12 | |
| 13 | assert.Equal(t, expectedResult, actualResult) |
| 14 | } |
| 15 | |
| 16 | func TestDurationWithZeroTimeout(t *testing.T) { |
| 17 | actualResult := GetDuration(0) |
| 18 | var expectedResult = defaultKVGetTimeout * time.Second |
| 19 | |
| 20 | assert.Equal(t, expectedResult, actualResult) |
| 21 | } |
| 22 | |
| 23 | func 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 | |
| 30 | func TestToStringWithString(t *testing.T) { |
| 31 | actualResult, _ := ToString("myString") |
| 32 | var expectedResult = "myString" |
| 33 | |
| 34 | assert.Equal(t, expectedResult, actualResult) |
| 35 | } |
| 36 | |
| 37 | func TestToStringWithEmpty(t *testing.T) { |
| 38 | actualResult, _ := ToString("") |
| 39 | var expectedResult = "" |
| 40 | |
| 41 | assert.Equal(t, expectedResult, actualResult) |
| 42 | } |
| 43 | |
| 44 | func 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 | |
| 52 | func TestToStringWithEmptyByte(t *testing.T) { |
| 53 | mByte := []byte("") |
| 54 | actualResult, _ := ToString(mByte) |
| 55 | var expectedResult = "" |
| 56 | |
| 57 | assert.Equal(t, expectedResult, actualResult) |
| 58 | } |
| 59 | |
| 60 | func 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 | } |