add file for linux specific tests
This commit is contained in:
parent
07a870e63b
commit
b3a9d75932
|
@ -0,0 +1,54 @@
|
|||
// +build linux
|
||||
|
||||
package process
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_Process_splitProcStat(t *testing.T) {
|
||||
expectedFieldsNum := 53
|
||||
statLineContent := make([]string, expectedFieldsNum-1)
|
||||
for i := 0; i < expectedFieldsNum-1; i++ {
|
||||
statLineContent[i] = strconv.Itoa(i + 1)
|
||||
}
|
||||
|
||||
cases := []string{
|
||||
"ok",
|
||||
"ok)",
|
||||
"(ok",
|
||||
"ok )",
|
||||
"ok )(",
|
||||
"ok )()",
|
||||
"() ok )()",
|
||||
"() ok (()",
|
||||
" ) ok )",
|
||||
"(ok) (ok)",
|
||||
}
|
||||
|
||||
consideredFields := []int{4, 7, 10, 11, 12, 13, 14, 15, 18, 22, 42}
|
||||
|
||||
commandNameIndex := 2
|
||||
for _, expectedName := range cases {
|
||||
statLineContent[commandNameIndex-1] = "(" + expectedName + ")"
|
||||
statLine := strings.Join(statLineContent, " ")
|
||||
t.Run(fmt.Sprintf("name: %s", expectedName), func(t *testing.T) {
|
||||
parsedStatLine := splitProcStat([]byte(statLine))
|
||||
assert.Equal(t, expectedName, parsedStatLine[commandNameIndex])
|
||||
for _, idx := range consideredFields {
|
||||
expected := strconv.Itoa(idx)
|
||||
parsed := parsedStatLine[idx]
|
||||
assert.Equal(
|
||||
t, expected, parsed,
|
||||
"field %d (index from 1 as in man proc) must be %q but %q is received",
|
||||
idx, expected, parsed,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -303,48 +303,6 @@ func Test_Process_Threads(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_Process_splitProcStat(t *testing.T) {
|
||||
expectedFieldsNum := 53
|
||||
statLineContent := make([]string, expectedFieldsNum-1)
|
||||
for i := 0; i < expectedFieldsNum-1; i++ {
|
||||
statLineContent[i] = strconv.Itoa(i + 1)
|
||||
}
|
||||
|
||||
cases := []string{
|
||||
"ok",
|
||||
"ok)",
|
||||
"(ok",
|
||||
"ok )",
|
||||
"ok )(",
|
||||
"ok )()",
|
||||
"() ok )()",
|
||||
"() ok (()",
|
||||
" ) ok )",
|
||||
"(ok) (ok)",
|
||||
}
|
||||
|
||||
consideredFields := []int{4, 7, 10, 11, 12, 13, 14, 15, 18, 22, 42}
|
||||
|
||||
commandNameIndex := 2
|
||||
for _, expectedName := range cases {
|
||||
statLineContent[commandNameIndex-1] = "(" + expectedName + ")"
|
||||
statLine := strings.Join(statLineContent, " ")
|
||||
t.Run(fmt.Sprintf("name: %s", expectedName), func(t *testing.T) {
|
||||
parsedStatLine := splitProcStat([]byte(statLine))
|
||||
assert.Equal(t, expectedName, parsedStatLine[commandNameIndex])
|
||||
for _, idx := range consideredFields {
|
||||
expected := strconv.Itoa(idx)
|
||||
parsed := parsedStatLine[idx]
|
||||
assert.Equal(
|
||||
t, expected, parsed,
|
||||
"field %d (index from 1 as in man proc) must be %q but %q is received",
|
||||
idx, expected, parsed,
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Process_Name(t *testing.T) {
|
||||
p := testGetProcess()
|
||||
|
||||
|
|
Loading…
Reference in New Issue