File: mountinfo_filters_test.go

package info (click to toggle)
golang-github-moby-sys 0.0~git20241107.638aa7c-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 616 kB
  • sloc: makefile: 58
file content (31 lines) | stat: -rw-r--r-- 931 bytes parent folder | download | duplicates (3)
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
package mountinfo

import "testing"

func TestPrefixFilter(t *testing.T) {
	tests := []struct {
		prefix     string
		mountPoint string
		shouldSkip bool
	}{
		{prefix: "/a", mountPoint: "/a", shouldSkip: false},
		{prefix: "/a", mountPoint: "/a/b", shouldSkip: false},
		{prefix: "/a", mountPoint: "/aa", shouldSkip: true},
		{prefix: "/a", mountPoint: "/aa/b", shouldSkip: true},

		// invalid prefix: prefix path must be cleaned and have no trailing slash
		{prefix: "/a/", mountPoint: "/a", shouldSkip: true},
		{prefix: "/a/", mountPoint: "/a/b", shouldSkip: true},
	}
	for _, tc := range tests {
		filter := PrefixFilter(tc.prefix)
		skip, _ := filter(&Info{Mountpoint: tc.mountPoint})
		if skip != tc.shouldSkip {
			if tc.shouldSkip {
				t.Errorf("prefix %q: expected %q to be skipped", tc.prefix, tc.mountPoint)
			} else {
				t.Errorf("prefix %q: expected %q not to be skipped", tc.prefix, tc.mountPoint)
			}
		}
	}
}