...

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

Documentation: github.com/prometheus/procfs

     1  // Copyright 2019 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  	"net"
    18  	"testing"
    19  )
    20  
    21  func TestARP(t *testing.T) {
    22  	fs, err := NewFS(procTestFixtures)
    23  	if err != nil {
    24  		t.Fatal(err)
    25  	}
    26  
    27  	arpFile, err := fs.GatherARPEntries()
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  
    32  	if want, got := "192.168.224.1", arpFile[0].IPAddr.String(); want != got {
    33  		t.Errorf("want 192.168.224.1, got %s", got)
    34  	}
    35  
    36  	if want, got := "00:50:56:c0:00:08", arpFile[0].HWAddr.String(); want != got {
    37  		t.Errorf("want %s, got %s", want, got)
    38  	}
    39  
    40  	if want, got := "ens33", arpFile[0].Device; want != got {
    41  		t.Errorf("want ens33, got %s", got)
    42  	}
    43  
    44  	if want, got := true, arpFile[0].IsComplete(); want != got {
    45  		t.Errorf("want %t, got %t", want, got)
    46  	}
    47  
    48  	if want, got := "192.168.224.2", arpFile[1].IPAddr.String(); want != got {
    49  		t.Errorf("want 192.168.224.2, got %s", got)
    50  	}
    51  
    52  	if want, got := make(net.HardwareAddr, 6).String(), arpFile[1].HWAddr.String(); want != got {
    53  		t.Errorf("expected empty MAC, got %s", got)
    54  	}
    55  
    56  	if want, got := "ens33", arpFile[1].Device; want != got {
    57  		t.Errorf("want %s, got %s", want, got)
    58  	}
    59  
    60  	if want, got := byte(0x0), arpFile[1].Flags; want != got {
    61  		t.Errorf("want %b, got %b", want, got)
    62  	}
    63  
    64  	if want, got := false, arpFile[1].IsComplete(); want != got {
    65  		t.Errorf("want %t, got %t", want, got)
    66  	}
    67  }
    68  

View as plain text