...

Source file src/github.com/prometheus/procfs/net_route_test.go

Documentation: github.com/prometheus/procfs

     1  // Copyright 2023 The Prometheus Authors
     2  // Licensed under the Apache License, Version 2.0 (the "License");
     3  // you may not use this file except in compliance with the License.
     4  // You may obtain a copy of the License at
     5  //
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package procfs
    15  
    16  import (
    17  	"bytes"
    18  	"reflect"
    19  	"testing"
    20  )
    21  
    22  func TestParseNetRoute(t *testing.T) {
    23  	var netRoute = []byte(`Iface            Destination  Gateway   Flags  RefCnt  Use  Metric  Mask      MTU  Window  IRTT
    24  eno16780032      00000000     9503A8C0  0003   0       0    100     00000000  0    0       0
    25  eno16780032      0000A8C0     00000000  0001   0       0    100     0000FFFF  0    0       0`)
    26  
    27  	r := bytes.NewReader(netRoute)
    28  	parsed, _ := parseNetRoute(r)
    29  	want := []NetRouteLine{
    30  		{
    31  			Iface:       "eno16780032",
    32  			Destination: 0,
    33  			Gateway:     2500044992,
    34  			Flags:       3,
    35  			RefCnt:      0,
    36  			Use:         0,
    37  			Metric:      100,
    38  			Mask:        0,
    39  			MTU:         0,
    40  			Window:      0,
    41  			IRTT:        0,
    42  		},
    43  		{
    44  			Iface:       "eno16780032",
    45  			Destination: 43200,
    46  			Gateway:     0,
    47  			Flags:       1,
    48  			RefCnt:      0,
    49  			Use:         0,
    50  			Metric:      100,
    51  			Mask:        65535,
    52  			MTU:         0,
    53  			Window:      0,
    54  			IRTT:        0,
    55  		},
    56  	}
    57  	if !reflect.DeepEqual(want, parsed) {
    58  		t.Errorf("want %v, parsed %v", want, parsed)
    59  	}
    60  }
    61  

View as plain text