Fix mode resolution tests

Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
Evan Lezar 2023-05-23 15:59:08 +02:00
parent e30fd0f4ad
commit fcb4e379e3

View File

@ -29,8 +29,9 @@ func TestResolveMode(t *testing.T) {
testCases := []struct { testCases := []struct {
mode string mode string
// TODO: This should be a proper mock isTegra bool
hasDXCore bool hasDXCore bool
hasNVML bool
expected string expected string
}{ }{
{ {
@ -41,11 +42,34 @@ func TestResolveMode(t *testing.T) {
{ {
mode: "auto", mode: "auto",
hasDXCore: false, hasDXCore: false,
isTegra: true,
hasNVML: false,
expected: "csv",
},
{
mode: "auto",
hasDXCore: false,
isTegra: false,
hasNVML: false,
expected: "nvml",
},
{
mode: "auto",
hasDXCore: false,
isTegra: true,
hasNVML: true,
expected: "nvml",
},
{
mode: "auto",
hasDXCore: false,
isTegra: false,
expected: "nvml", expected: "nvml",
}, },
{ {
mode: "nvml", mode: "nvml",
hasDXCore: true, hasDXCore: true,
isTegra: true,
expected: "nvml", expected: "nvml",
}, },
{ {
@ -65,7 +89,7 @@ func TestResolveMode(t *testing.T) {
l := nvcdilib{ l := nvcdilib{
logger: logger, logger: logger,
mode: tc.mode, mode: tc.mode,
infolib: infoMock(tc.hasDXCore), infolib: infoMock{hasDXCore: tc.hasDXCore, isTegra: tc.isTegra, hasNVML: tc.hasNVML},
} }
require.Equal(t, tc.expected, l.resolveMode()) require.Equal(t, tc.expected, l.resolveMode())
@ -73,16 +97,20 @@ func TestResolveMode(t *testing.T) {
} }
} }
type infoMock bool type infoMock struct {
hasDXCore bool
isTegra bool
hasNVML bool
}
func (i infoMock) HasDXCore() (bool, string) { func (i infoMock) HasDXCore() (bool, string) {
return bool(i), "" return bool(i.hasDXCore), ""
} }
func (i infoMock) HasNvml() (bool, string) { func (i infoMock) HasNvml() (bool, string) {
panic("should not be called") return bool(i.hasNVML), ""
} }
func (i infoMock) IsTegraSystem() (bool, string) { func (i infoMock) IsTegraSystem() (bool, string) {
panic("should not be called") return bool(i.isTegra), ""
} }