...

Source file src/github.com/prometheus/procfs/sysfs/class_sas_host_test.go

Documentation: github.com/prometheus/procfs/sysfs

     1  // Copyright 2021 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  //go:build linux
    15  // +build linux
    16  
    17  package sysfs
    18  
    19  import (
    20  	"testing"
    21  
    22  	"github.com/google/go-cmp/cmp"
    23  )
    24  
    25  func TestSASHostClass(t *testing.T) {
    26  	fs, err := NewFS(sysTestFixtures)
    27  	if err != nil {
    28  		t.Fatal(err)
    29  	}
    30  
    31  	got, err := fs.SASHostClass()
    32  	if err != nil {
    33  		t.Fatal(err)
    34  	}
    35  
    36  	want := SASHostClass{
    37  		"host11": &SASHost{
    38  			Name: "host11",
    39  			SASPhys: []string{
    40  				"phy-11:10", "phy-11:11", "phy-11:12", "phy-11:13",
    41  				"phy-11:14", "phy-11:15", "phy-11:7", "phy-11:8",
    42  				"phy-11:9",
    43  			},
    44  			SASPorts: []string{
    45  				"port-11:0", "port-11:1", "port-11:2",
    46  			},
    47  		},
    48  	}
    49  
    50  	if diff := cmp.Diff(want, got); diff != "" {
    51  		t.Fatalf("unexpected SASHost class (-want +got):\n%s", diff)
    52  	}
    53  }
    54  
    55  func TestSASHostGetByName(t *testing.T) {
    56  	fs, err := NewFS(sysTestFixtures)
    57  	if err != nil {
    58  		t.Fatal(err)
    59  	}
    60  
    61  	hc, err := fs.SASHostClass()
    62  	if err != nil {
    63  		t.Fatal(err)
    64  	}
    65  
    66  	want := "host11"
    67  	got := hc.GetByName("host11").Name
    68  	if diff := cmp.Diff(want, got); diff != "" {
    69  		t.Fatalf("unexpected SASHost class (-want +got):\n%s", diff)
    70  	}
    71  
    72  	// Doesn't exist.
    73  	got2 := hc.GetByName("host12")
    74  	if got2 != nil {
    75  		t.Fatalf("unexpected GetByName response: got %v want nil", got2)
    76  	}
    77  }
    78  
    79  func TestSASHostGetByPhy(t *testing.T) {
    80  	fs, err := NewFS(sysTestFixtures)
    81  	if err != nil {
    82  		t.Fatal(err)
    83  	}
    84  
    85  	hc, err := fs.SASHostClass()
    86  	if err != nil {
    87  		t.Fatal(err)
    88  	}
    89  
    90  	want := "host11"
    91  	got := hc.GetByPhy("phy-11:11").Name
    92  	if diff := cmp.Diff(want, got); diff != "" {
    93  		t.Fatalf("unexpected SASHost class (-want +got):\n%s", diff)
    94  	}
    95  
    96  	// Doesn't exist.
    97  	got2 := hc.GetByPhy("phy-12:0")
    98  	if got2 != nil {
    99  		t.Fatalf("unexpected GetByPhy response: got %v want nil", got2)
   100  	}
   101  }
   102  
   103  func TestSASHostGetByPort(t *testing.T) {
   104  	fs, err := NewFS(sysTestFixtures)
   105  	if err != nil {
   106  		t.Fatal(err)
   107  	}
   108  
   109  	hc, err := fs.SASHostClass()
   110  	if err != nil {
   111  		t.Fatal(err)
   112  	}
   113  
   114  	want := "host11"
   115  	got := hc.GetByPort("port-11:0").Name
   116  	if diff := cmp.Diff(want, got); diff != "" {
   117  		t.Fatalf("unexpected SASHost class (-want +got):\n%s", diff)
   118  	}
   119  
   120  	// Doesn't exist.
   121  	got2 := hc.GetByPort("port-12:0")
   122  	if got2 != nil {
   123  		t.Fatalf("unexpected GetByPhy response: got %v want nil", got2)
   124  	}
   125  }
   126  

View as plain text