khenaidoo | bf6e7bb | 2018-08-14 22:27:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 16 | package kvstore |
| 17 | |
| 18 | import ( |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 19 | "github.com/stretchr/testify/assert" |
khenaidoo | 5c11af7 | 2018-07-20 17:21:05 -0400 | [diff] [blame] | 20 | "testing" |
| 21 | "time" |
khenaidoo | cfee5f4 | 2018-07-19 22:47:38 -0400 | [diff] [blame] | 22 | ) |
| 23 | |
| 24 | func TestDurationWithNegativeTimeout(t *testing.T) { |
| 25 | actualResult := GetDuration(-1) |
| 26 | var expectedResult = defaultKVGetTimeout * time.Second |
| 27 | |
| 28 | assert.Equal(t, expectedResult, actualResult) |
| 29 | } |
| 30 | |
| 31 | func TestDurationWithZeroTimeout(t *testing.T) { |
| 32 | actualResult := GetDuration(0) |
| 33 | var expectedResult = defaultKVGetTimeout * time.Second |
| 34 | |
| 35 | assert.Equal(t, expectedResult, actualResult) |
| 36 | } |
| 37 | |
| 38 | func TestDurationWithTimeout(t *testing.T) { |
| 39 | actualResult := GetDuration(10) |
| 40 | var expectedResult = time.Duration(10) * time.Second |
| 41 | |
| 42 | assert.Equal(t, expectedResult, actualResult) |
| 43 | } |
| 44 | |
| 45 | func TestToStringWithString(t *testing.T) { |
| 46 | actualResult, _ := ToString("myString") |
| 47 | var expectedResult = "myString" |
| 48 | |
| 49 | assert.Equal(t, expectedResult, actualResult) |
| 50 | } |
| 51 | |
| 52 | func TestToStringWithEmpty(t *testing.T) { |
| 53 | actualResult, _ := ToString("") |
| 54 | var expectedResult = "" |
| 55 | |
| 56 | assert.Equal(t, expectedResult, actualResult) |
| 57 | } |
| 58 | |
| 59 | func TestToStringWithByte(t *testing.T) { |
| 60 | mByte := []byte("Hello") |
| 61 | actualResult, _ := ToString(mByte) |
| 62 | var expectedResult = "Hello" |
| 63 | |
| 64 | assert.Equal(t, expectedResult, actualResult) |
| 65 | } |
| 66 | |
| 67 | func TestToStringWithEmptyByte(t *testing.T) { |
| 68 | mByte := []byte("") |
| 69 | actualResult, _ := ToString(mByte) |
| 70 | var expectedResult = "" |
| 71 | |
| 72 | assert.Equal(t, expectedResult, actualResult) |
| 73 | } |
| 74 | |
| 75 | func TestToStringForErrorCase(t *testing.T) { |
| 76 | mInt := 200 |
| 77 | actualResult, error := ToString(mInt) |
| 78 | var expectedResult = "" |
| 79 | |
| 80 | assert.Equal(t, expectedResult, actualResult) |
| 81 | assert.NotEqual(t, error, nil) |
| 82 | } |