refactor: improve get ssh path duplicate code

Signed-off-by: Black-Hole1 <bh@bugs.cc>
This commit is contained in:
Black-Hole1
2023-05-31 16:27:19 +08:00
parent e91f6f16bf
commit c7a8d29f12
7 changed files with 42 additions and 49 deletions

View File

@ -2,9 +2,11 @@ package util
import (
"fmt"
"path/filepath"
"testing"
"time"
"github.com/containers/storage/pkg/homedir"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/stretchr/testify/assert"
)
@ -56,6 +58,12 @@ func TestValidateSysctlBadSysctlWithExtraSpaces(t *testing.T) {
assert.Equal(t, err.Error(), fmt.Sprintf(expectedError, strSlice2[1]))
}
func TestGetIdentityPath(t *testing.T) {
name := "p-test"
identityPath := GetIdentityPath(name)
assert.Equal(t, identityPath, filepath.Join(homedir.Get(), ".ssh", name))
}
func TestCoresToPeriodAndQuota(t *testing.T) {
cores := 1.0
expectedPeriod := DefaultCPUPeriod