...

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

Documentation: github.com/prometheus/procfs

     1  // Copyright 2022 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 "testing"
    17  
    18  func TestProcSnmp(t *testing.T) {
    19  	p, err := getProcFixtures(t).Proc(26231)
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  
    24  	procSnmp, err := p.Snmp()
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  
    29  	for _, test := range []struct {
    30  		name string
    31  		want float64
    32  		have float64
    33  	}{
    34  		{name: "pid", want: 26231, have: float64(procSnmp.PID)},
    35  		{name: "IP:Forwarding", want: 2, have: *procSnmp.Ip.Forwarding},
    36  		{name: "IP:DefaultTTL", want: 64, have: *procSnmp.Ip.DefaultTTL},
    37  		{name: "Icmp:InMsgs", want: 45, have: *procSnmp.Icmp.InMsgs},
    38  		{name: "IcmpMsg:InType3", want: 45, have: *procSnmp.IcmpMsg.InType3},
    39  		{name: "IcmpMsg:OutType3", want: 50, have: *procSnmp.IcmpMsg.OutType3},
    40  		{name: "TCP:RtoAlgorithm", want: 1, have: *procSnmp.Tcp.RtoAlgorithm},
    41  		{name: "TCP:RtoMin", want: 200, have: *procSnmp.Tcp.RtoMin},
    42  		{name: "Udp:InDatagrams", want: 10179, have: *procSnmp.Udp.InDatagrams},
    43  		{name: "Udp:NoPorts", want: 50, have: *procSnmp.Udp.NoPorts},
    44  		{name: "UdpLite:InDatagrams", want: 0, have: *procSnmp.UdpLite.NoPorts},
    45  		{name: "UdpLite:NoPorts", want: 0, have: *procSnmp.UdpLite.NoPorts},
    46  	} {
    47  		if test.want != test.have {
    48  			t.Errorf("want %s %f, have %f", test.name, test.want, test.have)
    49  		}
    50  	}
    51  
    52  }
    53  

View as plain text