...

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

Documentation: github.com/prometheus/procfs/sysfs

     1  // Copyright 2018 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 TestPowerSupplyClass(t *testing.T) {
    26  	fs, err := NewFS(sysTestFixtures)
    27  	if err != nil {
    28  		t.Fatalf("failed to open filesystem: %v", err)
    29  	}
    30  
    31  	got, err := fs.PowerSupplyClass()
    32  	if err != nil {
    33  		t.Fatalf("failed to parse power supply class: %v", err)
    34  	}
    35  
    36  	var (
    37  		acOnline             int64
    38  		bat0Capacity         int64 = 98
    39  		bat0CycleCount       int64
    40  		bat0EnergyFull       int64 = 50060000
    41  		bat0EnergyFullDesign int64 = 47520000
    42  		bat0EnergyNow        int64 = 49450000
    43  		bat0PowerNow         int64 = 4830000
    44  		bat0Present          int64 = 1
    45  		bat0VoltageMinDesign int64 = 10800000
    46  		bat0VoltageNow       int64 = 12229000
    47  	)
    48  
    49  	want := PowerSupplyClass{
    50  		"AC": {
    51  			Name:   "AC",
    52  			Type:   "Mains",
    53  			Online: &acOnline,
    54  		},
    55  		"BAT0": {
    56  			Name:             "BAT0",
    57  			Capacity:         &bat0Capacity,
    58  			CapacityLevel:    "Normal",
    59  			CycleCount:       &bat0CycleCount,
    60  			EnergyFull:       &bat0EnergyFull,
    61  			EnergyFullDesign: &bat0EnergyFullDesign,
    62  			EnergyNow:        &bat0EnergyNow,
    63  			Manufacturer:     "LGC",
    64  			ModelName:        "LNV-45N1",
    65  			PowerNow:         &bat0PowerNow,
    66  			Present:          &bat0Present,
    67  			SerialNumber:     "38109",
    68  			Status:           "Discharging",
    69  			Technology:       "Li-ion",
    70  			Type:             "Battery",
    71  			VoltageMinDesign: &bat0VoltageMinDesign,
    72  			VoltageNow:       &bat0VoltageNow,
    73  		},
    74  	}
    75  
    76  	if diff := cmp.Diff(want, got); diff != "" {
    77  		t.Fatalf("unexpected power supply class (-want +got):\n%s", diff)
    78  	}
    79  }
    80  

View as plain text