...

Source file src/github.com/prometheus/procfs/net_wireless_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  	"reflect"
    18  	"testing"
    19  )
    20  
    21  func TestWireless(t *testing.T) {
    22  	fs, err := NewFS(procTestFixtures)
    23  	if err != nil {
    24  		t.Fatalf("failed to open procfs: %v", err)
    25  	}
    26  
    27  	got, err := fs.Wireless()
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  
    32  	expected := []*Wireless{
    33  		{
    34  			Name:           "wlan0",
    35  			Status:         1,
    36  			QualityLink:    2,
    37  			QualityLevel:   3,
    38  			QualityNoise:   4,
    39  			DiscardedNwid:  5,
    40  			DiscardedCrypt: 6,
    41  			DiscardedFrag:  7,
    42  			DiscardedRetry: 8,
    43  			DiscardedMisc:  9,
    44  			MissedBeacon:   10,
    45  		},
    46  		{
    47  			Name:           "wlan1",
    48  			Status:         16,
    49  			QualityLink:    9,
    50  			QualityLevel:   8,
    51  			QualityNoise:   7,
    52  			DiscardedNwid:  6,
    53  			DiscardedCrypt: 5,
    54  			DiscardedFrag:  4,
    55  			DiscardedRetry: 3,
    56  			DiscardedMisc:  2,
    57  			MissedBeacon:   1,
    58  		},
    59  	}
    60  
    61  	if len(got) != len(expected) {
    62  		t.Fatalf("unexpected number of interfaces parsed %d, expected %d", len(got), len(expected))
    63  	}
    64  
    65  	for i, iface := range got {
    66  		if !reflect.DeepEqual(iface, expected[i]) {
    67  			t.Errorf("unexpected interface got %+v, expected %+v", iface, expected[i])
    68  		}
    69  	}
    70  }
    71  

View as plain text