mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-24 13:48:56 +08:00
parent
8ecc0c6804
commit
3748c19402
@ -138,13 +138,13 @@ func getlsbStruct(ctx context.Context) (*lsbStruct, error) {
|
||||
}
|
||||
switch field[0] {
|
||||
case "DISTRIB_ID":
|
||||
ret.ID = field[1]
|
||||
ret.ID = strings.ReplaceAll(field[1], `"`, ``)
|
||||
case "DISTRIB_RELEASE":
|
||||
ret.Release = field[1]
|
||||
ret.Release = strings.ReplaceAll(field[1], `"`, ``)
|
||||
case "DISTRIB_CODENAME":
|
||||
ret.Codename = field[1]
|
||||
ret.Codename = strings.ReplaceAll(field[1], `"`, ``)
|
||||
case "DISTRIB_DESCRIPTION":
|
||||
ret.Description = field[1]
|
||||
ret.Description = strings.ReplaceAll(field[1], `"`, ``)
|
||||
}
|
||||
}
|
||||
} else if common.PathExists("/usr/bin/lsb_release") {
|
||||
@ -159,13 +159,13 @@ func getlsbStruct(ctx context.Context) (*lsbStruct, error) {
|
||||
}
|
||||
switch field[0] {
|
||||
case "Distributor ID":
|
||||
ret.ID = field[1]
|
||||
ret.ID = strings.ReplaceAll(field[1], `"`, ``)
|
||||
case "Release":
|
||||
ret.Release = field[1]
|
||||
ret.Release = strings.ReplaceAll(field[1], `"`, ``)
|
||||
case "Codename":
|
||||
ret.Codename = field[1]
|
||||
ret.Codename = strings.ReplaceAll(field[1], `"`, ``)
|
||||
case "Description":
|
||||
ret.Description = field[1]
|
||||
ret.Description = strings.ReplaceAll(field[1], `"`, ``)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,10 @@
|
||||
package host
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/shirou/gopsutil/v3/common"
|
||||
)
|
||||
|
||||
func TestGetRedhatishVersion(t *testing.T) {
|
||||
@ -60,3 +63,45 @@ func TestGetRedhatishPlatform(t *testing.T) {
|
||||
t.Errorf("Could not get platform with no value: %v", ret)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_getlsbStruct(t *testing.T) {
|
||||
cases := []struct {
|
||||
root string
|
||||
id string
|
||||
release string
|
||||
codename string
|
||||
description string
|
||||
}{
|
||||
{"arch", "Arch", "rolling", "", "Arch Linux"},
|
||||
{"ubuntu_22_04", "Ubuntu", "22.04", "jammy", "Ubuntu 22.04.2 LTS"},
|
||||
}
|
||||
|
||||
for _, tt := range cases {
|
||||
tt := tt
|
||||
t.Run(tt.root, func(t *testing.T) {
|
||||
ctx := context.WithValue(context.Background(),
|
||||
common.EnvKey,
|
||||
common.EnvMap{common.HostEtcEnvKey: "./testdata/linux/lsbStruct/" + tt.root},
|
||||
)
|
||||
|
||||
v, err := getlsbStruct(ctx)
|
||||
if err != nil {
|
||||
t.Errorf("error %v", err)
|
||||
}
|
||||
if v.ID != tt.id {
|
||||
t.Errorf("ID: want %v, got %v", tt.id, v.ID)
|
||||
}
|
||||
if v.Release != tt.release {
|
||||
t.Errorf("Release: want %v, got %v", tt.release, v.Release)
|
||||
}
|
||||
if v.Codename != tt.codename {
|
||||
t.Errorf("Codename: want %v, got %v", tt.codename, v.Codename)
|
||||
}
|
||||
if v.Description != tt.description {
|
||||
t.Errorf("Description: want %v, got %v", tt.description, v.Description)
|
||||
}
|
||||
|
||||
t.Log(v)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ func TestHostInfo(t *testing.T) {
|
||||
if v.Procs == 0 {
|
||||
t.Errorf("Could not determine the number of host processes")
|
||||
}
|
||||
t.Log(v)
|
||||
}
|
||||
|
||||
func TestUptime(t *testing.T) {
|
||||
|
3
host/testdata/linux/lsbStruct/arch/lsb-release
vendored
Normal file
3
host/testdata/linux/lsbStruct/arch/lsb-release
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
DISTRIB_ID="Arch"
|
||||
DISTRIB_RELEASE="rolling"
|
||||
DISTRIB_DESCRIPTION="Arch Linux"
|
4
host/testdata/linux/lsbStruct/ubuntu_22_04/lsb-release
vendored
Normal file
4
host/testdata/linux/lsbStruct/ubuntu_22_04/lsb-release
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
DISTRIB_ID=Ubuntu
|
||||
DISTRIB_RELEASE=22.04
|
||||
DISTRIB_CODENAME=jammy
|
||||
DISTRIB_DESCRIPTION="Ubuntu 22.04.2 LTS"
|
Loading…
x
Reference in New Issue
Block a user