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