go.ligato.io/vpp-agent/v3@v3.5.0/plugins/vpp/ifplugin/vppcalls/vpp2106/dump_interface_status_test.go (about)

     1  //  Copyright (c) 2021 Cisco and/or its affiliates.
     2  //
     3  //  Licensed under the Apache License, Version 2.0 (the "License");
     4  //  you may not use this file except in compliance with the License.
     5  //  You may obtain a copy of the License at:
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  //  Unless required by applicable law or agreed to in writing, software
    10  //  distributed under the License is distributed on an "AS IS" BASIS,
    11  //  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  //  See the License for the specific language governing permissions and
    13  //  limitations under the License.
    14  
    15  package vpp2106
    16  
    17  import (
    18  	"testing"
    19  
    20  	"go.ligato.io/vpp-agent/v3/plugins/vpp/binapi/vpp2106/interface_types"
    21  	ifs "go.ligato.io/vpp-agent/v3/proto/ligato/vpp/interfaces"
    22  )
    23  
    24  func TestIsAdminStateUp(t *testing.T) {
    25  	tests := []struct {
    26  		input interface_types.IfStatusFlags
    27  		want  bool
    28  	}{
    29  		{input: 0, want: false},
    30  		{input: 1, want: true},
    31  		{input: 2, want: false},
    32  		{input: 3, want: true},
    33  		{input: 4, want: false},
    34  		{input: 5, want: true},
    35  		{input: 6, want: false},
    36  	}
    37  
    38  	for _, tc := range tests {
    39  		got := isAdminStateUp(tc.input)
    40  		if tc.want != got {
    41  			t.Fatalf("for input: %d, want: %v, got: %v", tc.input, tc.want, got)
    42  		}
    43  	}
    44  }
    45  
    46  func TestIsLinkStateUp(t *testing.T) {
    47  	tests := []struct {
    48  		input interface_types.IfStatusFlags
    49  		want  bool
    50  	}{
    51  		{input: 0, want: false},
    52  		{input: 1, want: false},
    53  		{input: 2, want: true},
    54  		{input: 3, want: true},
    55  		{input: 4, want: false},
    56  		{input: 5, want: false},
    57  		{input: 6, want: true},
    58  	}
    59  
    60  	for _, tc := range tests {
    61  		got := isLinkStateUp(tc.input)
    62  		if tc.want != got {
    63  			t.Fatalf("for input: %d, want: %v, got: %v", tc.input, tc.want, got)
    64  		}
    65  	}
    66  }
    67  
    68  func TestAdminStateToInterfaceStatus(t *testing.T) {
    69  	tests := []struct {
    70  		input interface_types.IfStatusFlags
    71  		want  ifs.InterfaceState_Status
    72  	}{
    73  		{input: 0, want: ifs.InterfaceState_DOWN},
    74  		{input: 1, want: ifs.InterfaceState_UP},
    75  		{input: 2, want: ifs.InterfaceState_DOWN},
    76  		{input: 3, want: ifs.InterfaceState_UP},
    77  		{input: 4, want: ifs.InterfaceState_DOWN},
    78  	}
    79  
    80  	for _, tc := range tests {
    81  		got := adminStateToInterfaceStatus(tc.input)
    82  		if tc.want != got {
    83  			t.Fatalf("for input: %d, want: %v, got: %v", tc.input, tc.want, got)
    84  		}
    85  	}
    86  }
    87  
    88  func TestLinkStateToInterfaceStatus(t *testing.T) {
    89  	tests := []struct {
    90  		input interface_types.IfStatusFlags
    91  		want  ifs.InterfaceState_Status
    92  	}{
    93  		{input: 0, want: ifs.InterfaceState_DOWN},
    94  		{input: 1, want: ifs.InterfaceState_DOWN},
    95  		{input: 2, want: ifs.InterfaceState_UP},
    96  		{input: 3, want: ifs.InterfaceState_UP},
    97  		{input: 4, want: ifs.InterfaceState_DOWN},
    98  	}
    99  
   100  	for _, tc := range tests {
   101  		got := linkStateToInterfaceStatus(tc.input)
   102  		if tc.want != got {
   103  			t.Fatalf("for input: %d, want: %v, got: %v", tc.input, tc.want, got)
   104  		}
   105  	}
   106  }