You've already forked runc
mirror of
https://github.com/opencontainers/runc.git
synced 2025-08-08 12:42:06 +03:00
Add tests for GetHugePageSize
Add tests to avoid regressions Signed-off-by: Odin Ugedal <odin@ugedal.com>
This commit is contained in:
@@ -4,6 +4,7 @@ package cgroups
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -421,3 +422,38 @@ func TestFindCgroupMountpointAndRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetHugePageSizeImpl(t *testing.T) {
|
||||
|
||||
testCases := []struct {
|
||||
inputFiles []string
|
||||
outputPageSizes []string
|
||||
err error
|
||||
}{
|
||||
{
|
||||
inputFiles: []string{"hugepages-1048576kB", "hugepages-2048kB", "hugepages-32768kB", "hugepages-64kB"},
|
||||
outputPageSizes: []string{"1GB", "2MB", "32MB", "64KB"},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
inputFiles: []string{},
|
||||
outputPageSizes: []string{},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
inputFiles: []string{"hugepages-a"},
|
||||
outputPageSizes: []string{},
|
||||
err: errors.New("invalid size: 'a'"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range testCases {
|
||||
pageSizes, err := getHugePageSizeFromFilenames(c.inputFiles)
|
||||
if len(pageSizes) != 0 && len(c.outputPageSizes) != 0 && !reflect.DeepEqual(pageSizes, c.outputPageSizes) {
|
||||
t.Errorf("expected %s, got %s", c.outputPageSizes, pageSizes)
|
||||
}
|
||||
if err != nil && err.Error() != c.err.Error() {
|
||||
t.Errorf("expected error %s, got %s", c.err, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user