Skip to content

Commit cacf199

Browse files
committed
Move substituteUVMPath to test specific go files
This function is now only used by tests, and having it in non _test files causses unused function lints. Signed-off-by: Tingmao Wang <[email protected]>
1 parent 1ddb6f4 commit cacf199

File tree

4 files changed

+24
-29
lines changed

4 files changed

+24
-29
lines changed

pkg/securitypolicy/regopolicy_linux_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"testing"
1818
"testing/quick"
1919

20+
specInternal "github.com/Microsoft/hcsshim/internal/guest/spec"
21+
"github.com/Microsoft/hcsshim/internal/guestpath"
2022
rpi "github.com/Microsoft/hcsshim/internal/regopolicyinterpreter"
2123
oci "github.com/opencontainers/runtime-spec/specs-go"
2224
)
@@ -6324,3 +6326,15 @@ func testGetUserInfo(t *testing.T, tc getUserInfoTestCase, userStr string, regoE
63246326
}
63256327
})
63266328
}
6329+
6330+
// substituteUVMPath substitutes mount prefix to an appropriate path inside
6331+
// UVM. At policy generation time, it's impossible to tell what the sandboxID
6332+
// will be, so the prefix substitution needs to happen during runtime.
6333+
func substituteUVMPath(sandboxID string, m mountInternal) mountInternal {
6334+
if strings.HasPrefix(m.Source, guestpath.SandboxMountPrefix) {
6335+
m.Source = specInternal.SandboxMountSource(sandboxID, m.Source)
6336+
} else if strings.HasPrefix(m.Source, guestpath.HugePagesMountPrefix) {
6337+
m.Source = specInternal.HugePagesMountSource(sandboxID, m.Source)
6338+
}
6339+
return m
6340+
}

pkg/securitypolicy/regopolicy_windows_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,3 +1329,13 @@ func Test_Rego_DumpStacksPolicy_Off(t *testing.T) {
13291329
t.Errorf("Test_Rego_DumpStacksPolicy_Off: %v", err)
13301330
}
13311331
}
1332+
1333+
// This is a no-op for windows.
1334+
// substituteUVMPath substitutes mount prefix to an appropriate path inside
1335+
// UVM. At policy generation time, it's impossible to tell what the sandboxID
1336+
// will be, so the prefix substitution needs to happen during runtime.
1337+
func substituteUVMPath(sandboxID string, m mountInternal) mountInternal {
1338+
//no-op for windows
1339+
_ = sandboxID
1340+
return m
1341+
}

pkg/securitypolicy/securitypolicy_linux.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import (
88
"os"
99
"path/filepath"
1010
"strconv"
11-
"strings"
1211

1312
specInternal "github.com/Microsoft/hcsshim/internal/guest/spec"
14-
"github.com/Microsoft/hcsshim/internal/guestpath"
1513
"github.com/moby/sys/user"
1614
oci "github.com/opencontainers/runtime-spec/specs-go"
1715
"github.com/pkg/errors"
@@ -20,21 +18,6 @@ import (
2018
//nolint:unused
2119
const osType = "linux"
2220

23-
// This is being used by StandEnforcer.
24-
// substituteUVMPath substitutes mount prefix to an appropriate path inside
25-
// UVM. At policy generation time, it's impossible to tell what the sandboxID
26-
// will be, so the prefix substitution needs to happen during runtime.
27-
//
28-
//nolint:unused // linting is wrong, this is used in rego_utils_test.go
29-
func substituteUVMPath(sandboxID string, m mountInternal) mountInternal {
30-
if strings.HasPrefix(m.Source, guestpath.SandboxMountPrefix) {
31-
m.Source = specInternal.SandboxMountSource(sandboxID, m.Source)
32-
} else if strings.HasPrefix(m.Source, guestpath.HugePagesMountPrefix) {
33-
m.Source = specInternal.HugePagesMountSource(sandboxID, m.Source)
34-
}
35-
return m
36-
}
37-
3821
// SandboxMountsDir returns sandbox mounts directory inside UVM/host.
3922
func SandboxMountsDir(sandboxID string) string {
4023
return specInternal.SandboxMountsDir((sandboxID))

pkg/securitypolicy/securitypolicy_windows.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,6 @@ import oci "github.com/opencontainers/runtime-spec/specs-go"
88
//nolint:unused
99
const osType = "windows"
1010

11-
// This is being used by StandEnforcer and is a no-op for windows.
12-
// substituteUVMPath substitutes mount prefix to an appropriate path inside
13-
// UVM. At policy generation time, it's impossible to tell what the sandboxID
14-
// will be, so the prefix substitution needs to happen during runtime.
15-
//
16-
//nolint:unused // linting is wrong, this is used in rego_utils_test.go
17-
func substituteUVMPath(sandboxID string, m mountInternal) mountInternal {
18-
//no-op for windows
19-
_ = sandboxID
20-
return m
21-
}
22-
2311
// SandboxMountsDir returns sandbox mounts directory inside UVM/host.
2412
func SandboxMountsDir(sandboxID string) string {
2513
return ""

0 commit comments

Comments
 (0)