| 1 | package main |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestParseCPUModel(t *testing.T) { |
| 6 | cpuinfo := "processor\t: 0\nvendor_id\t: GenuineIntel\nmodel name\t: Intel(R) Core(TM) i7-12700K\nflags\t: fpu vme\n" |
| 7 | if got := parseCPUModel(cpuinfo); got != "Intel(R) Core(TM) i7-12700K" { |
| 8 | t.Errorf("parseCPUModel = %q", got) |
| 9 | } |
| 10 | if got := parseCPUModel("no such field"); got != "" { |
| 11 | t.Errorf("parseCPUModel on garbage = %q, want empty", got) |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | func TestParseMemTotalBytes(t *testing.T) { |
| 16 | meminfo := "MemTotal: 32652284 kB\nMemFree: 1234 kB\n" |
| 17 | if got := parseMemTotalBytes(meminfo); got != 32652284*1024 { |
| 18 | t.Errorf("parseMemTotalBytes = %d", got) |
| 19 | } |
| 20 | if got := parseMemTotalBytes("MemFree: 1 kB"); got != 0 { |
| 21 | t.Errorf("parseMemTotalBytes without MemTotal = %d, want 0", got) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | func TestParseOSReleasePrettyName(t *testing.T) { |
| 26 | osRelease := "NAME=\"Ubuntu\"\nPRETTY_NAME=\"Ubuntu 24.04.1 LTS\"\nID=ubuntu\n" |
| 27 | if got := parseOSReleasePrettyName(osRelease); got != "Ubuntu 24.04.1 LTS" { |
| 28 | t.Errorf("parseOSReleasePrettyName = %q", got) |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func TestCollectDeviceInfoSane(t *testing.T) { |
| 33 | d := collectDeviceInfo() |
| 34 | if d.Cores < 1 { |
| 35 | t.Errorf("Cores = %d", d.Cores) |
| 36 | } |
| 37 | if d.OSVersion == "" { |
| 38 | t.Error("OSVersion empty") |
| 39 | } |
| 40 | } |
| 41 |