File: util_linux_test.go

package info (click to toggle)
podman 5.4.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,124 kB
  • sloc: sh: 6,119; perl: 2,710; python: 2,258; ansic: 1,556; makefile: 1,022; xml: 121; ruby: 42; awk: 12; csh: 8
file content (41 lines) | stat: -rw-r--r-- 1,045 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//go:build !remote

package libpod

import (
	"syscall"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestLabelVolumePath(t *testing.T) {
	// Set up mocked SELinux functions for testing.
	oldRelabel := lvpRelabel
	oldInitLabels := lvpInitLabels
	oldReleaseLabel := lvpReleaseLabel
	defer func() {
		lvpRelabel = oldRelabel
		lvpInitLabels = oldInitLabels
		lvpReleaseLabel = oldReleaseLabel
	}()

	// Relabel returns ENOTSUP unconditionally.
	lvpRelabel = func(path string, fileLabel string, shared bool) error {
		return syscall.ENOTSUP
	}

	// InitLabels and ReleaseLabel both return dummy values and nil errors.
	lvpInitLabels = func(options []string) (string, string, error) {
		pLabel := "system_u:system_r:container_t:s0:c1,c2"
		mLabel := "system_u:object_r:container_file_t:s0:c1,c2"
		return pLabel, mLabel, nil
	}
	lvpReleaseLabel = func(label string) error {
		return nil
	}

	// LabelVolumePath should not return an error if the operation is unsupported.
	err := LabelVolumePath("/foo/bar", "")
	assert.NoError(t, err)
}