blob: 86c4369f9956b3371484afac423c82c57d125a06 [file] [log] [blame]
khenaidoobf6e7bb2018-08-14 22:27:29 -04001/*
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 */
khenaidoocfee5f42018-07-19 22:47:38 -040016package kvstore
17
18import (
khenaidoocfee5f42018-07-19 22:47:38 -040019 "github.com/stretchr/testify/assert"
khenaidoo5c11af72018-07-20 17:21:05 -040020 "testing"
21 "time"
khenaidoocfee5f42018-07-19 22:47:38 -040022)
23
24func TestDurationWithNegativeTimeout(t *testing.T) {
25 actualResult := GetDuration(-1)
26 var expectedResult = defaultKVGetTimeout * time.Second
27
28 assert.Equal(t, expectedResult, actualResult)
29}
30
31func TestDurationWithZeroTimeout(t *testing.T) {
32 actualResult := GetDuration(0)
33 var expectedResult = defaultKVGetTimeout * time.Second
34
35 assert.Equal(t, expectedResult, actualResult)
36}
37
38func 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
45func TestToStringWithString(t *testing.T) {
46 actualResult, _ := ToString("myString")
47 var expectedResult = "myString"
48
49 assert.Equal(t, expectedResult, actualResult)
50}
51
52func TestToStringWithEmpty(t *testing.T) {
53 actualResult, _ := ToString("")
54 var expectedResult = ""
55
56 assert.Equal(t, expectedResult, actualResult)
57}
58
59func 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
67func TestToStringWithEmptyByte(t *testing.T) {
68 mByte := []byte("")
69 actualResult, _ := ToString(mByte)
70 var expectedResult = ""
71
72 assert.Equal(t, expectedResult, actualResult)
73}
74
75func 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}