ashokrad | 4322d61 | 2019-12-05 19:01:17 +0530 | [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 | |
| 17 | package afrouter |
| 18 | |
| 19 | import ( |
| 20 | "github.com/stretchr/testify/assert" |
| 21 | "testing" |
| 22 | ) |
| 23 | |
| 24 | //function to test Marshal and UnMarshal JSON of backend Type |
| 25 | func Test_backendType(t *testing.T) { |
| 26 | t_backendType1 := backendType(1) |
| 27 | backend_Str1, err := t_backendType1.MarshalJSON() |
| 28 | assert.Equal(t, string(backend_Str1), "\"active_active\"") |
| 29 | assert.Equal(t, err, nil) |
| 30 | |
| 31 | t_backendType2 := backendType(2) |
| 32 | backend_Str2, err := t_backendType2.MarshalJSON() |
| 33 | assert.Equal(t, string(backend_Str2), "\"server\"") |
| 34 | assert.Equal(t, err, nil) |
| 35 | |
| 36 | t_backendStr1 := backendType(1) |
| 37 | backend_Type1 := t_backendStr1.UnmarshalJSON([]byte("\"active_active\"")) |
| 38 | assert.Equal(t, backend_Type1, nil) |
| 39 | |
| 40 | t_backendStr2 := backendType(2) |
| 41 | backend_Type2 := t_backendStr2.UnmarshalJSON([]byte("\"server\"")) |
| 42 | assert.Equal(t, backend_Type2, nil) |
| 43 | |
| 44 | } |
| 45 | |
| 46 | //function to test Marshal and UnMarshal JSON of association Location |
| 47 | func Test_AssociationLocation(t *testing.T) { |
| 48 | t_assocLoc1 := associationLocation(1) |
| 49 | assoc_Str1, err := t_assocLoc1.MarshalJSON() |
| 50 | assert.Equal(t, string(assoc_Str1), "\"header\"") |
| 51 | assert.Equal(t, err, nil) |
| 52 | |
| 53 | t_assocLoc2 := associationLocation(2) |
| 54 | assoc_Str2, err := t_assocLoc2.MarshalJSON() |
| 55 | assert.Equal(t, string(assoc_Str2), "\"protobuf\"") |
| 56 | assert.Equal(t, err, nil) |
| 57 | |
| 58 | t_assocStr1 := associationLocation(1) |
| 59 | assoc_Loc1 := t_assocStr1.UnmarshalJSON([]byte("\"header\"")) |
| 60 | assert.Equal(t, assoc_Loc1, nil) |
| 61 | |
| 62 | t_assocStr2 := associationLocation(2) |
| 63 | assoc_Loc2 := t_assocStr2.UnmarshalJSON([]byte("\"protobuf\"")) |
| 64 | assert.Equal(t, assoc_Loc2, nil) |
| 65 | } |
| 66 | |
| 67 | //function to test Marshal and UnMarshal JSON of assoc Loc strategy |
| 68 | func Test_AssociationStrategy(t *testing.T) { |
| 69 | t_assocStrat1 := associationStrategy(1) |
| 70 | assocstrat_Str1, err := t_assocStrat1.MarshalJSON() |
| 71 | assert.Equal(t, string(assocstrat_Str1), "\"serial_number\"") |
| 72 | assert.Equal(t, err, nil) |
| 73 | |
| 74 | t_assocstratStr1 := associationStrategy(1) |
| 75 | assocstrat1 := t_assocstratStr1.UnmarshalJSON([]byte("\"serial_number\"")) |
| 76 | assert.Equal(t, assocstrat1, nil) |
| 77 | } |
| 78 | |
| 79 | //function to test Marshal and UnMarshal JSON of route type |
| 80 | func Test_RouteType(t *testing.T) { |
| 81 | t_routetyp1 := routeType(1) |
| 82 | routetyp_Str1, err := t_routetyp1.MarshalJSON() |
| 83 | assert.Equal(t, string(routetyp_Str1), "\"rpc_affinity_message\"") |
| 84 | assert.Equal(t, err, nil) |
| 85 | |
| 86 | t_routetyp2 := routeType(2) |
| 87 | routetyp_Str2, err := t_routetyp2.MarshalJSON() |
| 88 | assert.Equal(t, string(routetyp_Str2), "\"rpc_affinity_header\"") |
| 89 | assert.Equal(t, err, nil) |
| 90 | |
| 91 | t_routetyp3 := routeType(3) |
| 92 | routetyp_Str3, err := t_routetyp3.MarshalJSON() |
| 93 | assert.Equal(t, string(routetyp_Str3), "\"binding\"") |
| 94 | assert.Equal(t, err, nil) |
| 95 | |
| 96 | t_routetyp4 := routeType(4) |
| 97 | routetyp_Str4, err := t_routetyp4.MarshalJSON() |
| 98 | assert.Equal(t, string(routetyp_Str4), "\"round_robin\"") |
| 99 | assert.Equal(t, err, nil) |
| 100 | |
| 101 | t_routetyp5 := routeType(5) |
| 102 | routetyp_Str5, err := t_routetyp5.MarshalJSON() |
| 103 | assert.Equal(t, string(routetyp_Str5), "\"source\"") |
| 104 | assert.Equal(t, err, nil) |
| 105 | |
| 106 | t_routeStr1 := routeType(1) |
| 107 | routeType1 := t_routeStr1.UnmarshalJSON([]byte("\"rpc_affinity_message\"")) |
| 108 | assert.Equal(t, routeType1, nil) |
| 109 | |
| 110 | t_routeStr2 := routeType(2) |
| 111 | routeType2 := t_routeStr2.UnmarshalJSON([]byte("\"rpc_affinity_header\"")) |
| 112 | assert.Equal(t, routeType2, nil) |
| 113 | |
| 114 | t_routeStr3 := routeType(3) |
| 115 | routeType3 := t_routeStr3.UnmarshalJSON([]byte("\"binding\"")) |
| 116 | assert.Equal(t, routeType3, nil) |
| 117 | |
| 118 | t_routeStr4 := routeType(4) |
| 119 | routeType4 := t_routeStr4.UnmarshalJSON([]byte("\"round_robin\"")) |
| 120 | assert.Equal(t, routeType4, nil) |
| 121 | |
| 122 | t_routeStr5 := routeType(5) |
| 123 | routeType5 := t_routeStr5.UnmarshalJSON([]byte("\"source\"")) |
| 124 | assert.Equal(t, routeType5, nil) |
| 125 | } |
| 126 | |
| 127 | //function to test Marshal and UnMarshal JSON of Assoc type |
| 128 | func Test_AssociationType(t *testing.T) { |
| 129 | t_assocType1 := associationType(1) |
| 130 | assocStr1, err := t_assocType1.MarshalJSON() |
| 131 | assert.Equal(t, string(assocStr1), "\"round_robin\"") |
| 132 | assert.Equal(t, err, nil) |
| 133 | |
| 134 | t_assocStr1 := associationType(1) |
| 135 | assocType1 := t_assocStr1.UnmarshalJSON([]byte("\"round_robin\"")) |
| 136 | assert.Equal(t, assocType1, nil) |
| 137 | } |