1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package sysinfo
import (
"os"
"regexp"
"strconv"
"testing"
"github.com/newrelic/go-agent/v3/internal/crossagent"
)
func TestMemTotal(t *testing.T) {
var fileRe = regexp.MustCompile(`meminfo_([0-9]+)MB.txt$`)
var ignoreFile = regexp.MustCompile(`README\.md$`)
testCases, err := crossagent.ReadDir("proc_meminfo")
if err != nil {
t.Fatal(err)
}
for _, testFile := range testCases {
if ignoreFile.MatchString(testFile) {
continue
}
matches := fileRe.FindStringSubmatch(testFile)
if matches == nil || len(matches) < 2 {
t.Error(testFile, matches)
continue
}
expect, err := strconv.ParseUint(matches[1], 10, 64)
if err != nil {
t.Error(err)
continue
}
input, err := os.Open(testFile)
if err != nil {
t.Error(err)
continue
}
bts, err := parseProcMeminfo(input)
input.Close()
mib := BytesToMebibytes(bts)
if err != nil {
t.Error(err)
} else if mib != expect {
t.Error(bts, expect)
}
}
}
|