Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [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 | */ |
| 16 | package kvstore |
| 17 | |
| 18 | import ( |
| 19 | "github.com/stretchr/testify/assert" |
| 20 | "testing" |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 21 | ) |
| 22 | |
Scott Baker | 2c1c482 | 2019-10-16 11:02:41 -0700 | [diff] [blame] | 23 | func TestToStringWithString(t *testing.T) { |
| 24 | actualResult, _ := ToString("myString") |
| 25 | var expectedResult = "myString" |
| 26 | |
| 27 | assert.Equal(t, expectedResult, actualResult) |
| 28 | } |
| 29 | |
| 30 | func TestToStringWithEmpty(t *testing.T) { |
| 31 | actualResult, _ := ToString("") |
| 32 | var expectedResult = "" |
| 33 | |
| 34 | assert.Equal(t, expectedResult, actualResult) |
| 35 | } |
| 36 | |
| 37 | func TestToStringWithByte(t *testing.T) { |
| 38 | mByte := []byte("Hello") |
| 39 | actualResult, _ := ToString(mByte) |
| 40 | var expectedResult = "Hello" |
| 41 | |
| 42 | assert.Equal(t, expectedResult, actualResult) |
| 43 | } |
| 44 | |
| 45 | func TestToStringWithEmptyByte(t *testing.T) { |
| 46 | mByte := []byte("") |
| 47 | actualResult, _ := ToString(mByte) |
| 48 | var expectedResult = "" |
| 49 | |
| 50 | assert.Equal(t, expectedResult, actualResult) |
| 51 | } |
| 52 | |
| 53 | func TestToStringForErrorCase(t *testing.T) { |
| 54 | mInt := 200 |
| 55 | actualResult, error := ToString(mInt) |
| 56 | var expectedResult = "" |
| 57 | |
| 58 | assert.Equal(t, expectedResult, actualResult) |
| 59 | assert.NotEqual(t, error, nil) |
| 60 | } |