add test case for kubeadm memory check

Signed-off-by: Xianglin Gao <xianglin.gxl@alibaba-inc.com>
This commit is contained in:
Xianglin Gao
2020-07-20 23:59:57 +08:00
parent e5bb66f899
commit c6975a7750
9 changed files with 61 additions and 15 deletions

View File

@@ -20,6 +20,7 @@ import (
"bytes"
"fmt"
"io/ioutil"
"runtime"
"strings"
"testing"
@@ -849,3 +850,29 @@ func TestNumCPUCheck(t *testing.T) {
})
}
}
func TestMemCheck(t *testing.T) {
// skip this test, if OS in not Linux, since it will ONLY pass on Linux.
if runtime.GOOS != "linux" {
t.Skip("unsupported OS for memory check test ")
}
var tests = []struct {
minimum uint64
expectedErrors int
}{
{0, 0},
{9999999999999999, 1},
}
for _, rt := range tests {
t.Run(fmt.Sprintf("MemoryCheck{%d}", rt.minimum), func(t *testing.T) {
warnings, errors := MemCheck{Mem: rt.minimum}.Check()
if len(warnings) > 0 {
t.Errorf("expected 0 warnings but got %d: %q", len(warnings), warnings)
} else if len(errors) != rt.expectedErrors {
t.Errorf("expected %d error(s) but got %d: %q", rt.expectedErrors, len(errors), errors)
}
})
}
}