mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-06-26 18:18:24 +00:00
Add tools/container/operator package to handle runtime naming
Signed-off-by: Evan Lezar <elezar@nvidia.com>
This commit is contained in:
151
tools/container/operator/operator_test.go
Normal file
151
tools/container/operator/operator_test.go
Normal file
@@ -0,0 +1,151 @@
|
||||
/**
|
||||
# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
*/
|
||||
|
||||
package operator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOptions(t *testing.T) {
|
||||
testCases := []struct {
|
||||
setAsDefault bool
|
||||
nvidiaRuntimeName string
|
||||
root string
|
||||
expectedDefaultRuntime string
|
||||
expectedRuntimes Runtimes
|
||||
}{
|
||||
{
|
||||
expectedRuntimes: Runtimes{
|
||||
"nvidia": Runtime{
|
||||
name: "nvidia",
|
||||
Path: "/usr/bin/nvidia-container-runtime",
|
||||
},
|
||||
"nvidia-experimental": Runtime{
|
||||
name: "nvidia-experimental",
|
||||
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
setAsDefault: true,
|
||||
expectedDefaultRuntime: "nvidia",
|
||||
expectedRuntimes: Runtimes{
|
||||
"nvidia": Runtime{
|
||||
name: "nvidia",
|
||||
Path: "/usr/bin/nvidia-container-runtime",
|
||||
SetAsDefault: true,
|
||||
},
|
||||
"nvidia-experimental": Runtime{
|
||||
name: "nvidia-experimental",
|
||||
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
setAsDefault: true,
|
||||
nvidiaRuntimeName: "nvidia",
|
||||
expectedDefaultRuntime: "nvidia",
|
||||
expectedRuntimes: Runtimes{
|
||||
"nvidia": Runtime{
|
||||
name: "nvidia",
|
||||
Path: "/usr/bin/nvidia-container-runtime",
|
||||
SetAsDefault: true,
|
||||
},
|
||||
"nvidia-experimental": Runtime{
|
||||
name: "nvidia-experimental",
|
||||
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
setAsDefault: true,
|
||||
nvidiaRuntimeName: "NAME",
|
||||
expectedDefaultRuntime: "NAME",
|
||||
expectedRuntimes: Runtimes{
|
||||
"NAME": Runtime{
|
||||
name: "NAME",
|
||||
Path: "/usr/bin/nvidia-container-runtime",
|
||||
SetAsDefault: true,
|
||||
},
|
||||
"nvidia-experimental": Runtime{
|
||||
name: "nvidia-experimental",
|
||||
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
setAsDefault: false,
|
||||
nvidiaRuntimeName: "NAME",
|
||||
expectedRuntimes: Runtimes{
|
||||
"NAME": Runtime{
|
||||
name: "NAME",
|
||||
Path: "/usr/bin/nvidia-container-runtime",
|
||||
},
|
||||
"nvidia-experimental": Runtime{
|
||||
name: "nvidia-experimental",
|
||||
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
setAsDefault: true,
|
||||
nvidiaRuntimeName: "nvidia-experimental",
|
||||
expectedDefaultRuntime: "nvidia-experimental",
|
||||
expectedRuntimes: Runtimes{
|
||||
"nvidia": Runtime{
|
||||
name: "nvidia",
|
||||
Path: "/usr/bin/nvidia-container-runtime",
|
||||
},
|
||||
"nvidia-experimental": Runtime{
|
||||
name: "nvidia-experimental",
|
||||
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
||||
SetAsDefault: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
setAsDefault: false,
|
||||
nvidiaRuntimeName: "nvidia-experimental",
|
||||
expectedRuntimes: Runtimes{
|
||||
"nvidia": Runtime{
|
||||
name: "nvidia",
|
||||
Path: "/usr/bin/nvidia-container-runtime",
|
||||
},
|
||||
"nvidia-experimental": Runtime{
|
||||
name: "nvidia-experimental",
|
||||
Path: "/usr/bin/nvidia-container-runtime.experimental",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||
runtimes := GetRuntimes(
|
||||
WithNvidiaRuntimeName(tc.nvidiaRuntimeName),
|
||||
WithSetAsDefault(tc.setAsDefault),
|
||||
WithRoot(tc.root),
|
||||
)
|
||||
|
||||
require.EqualValues(t, tc.expectedRuntimes, runtimes)
|
||||
require.Equal(t, tc.expectedDefaultRuntime, runtimes.DefaultRuntimeName())
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user