...

Source file src/github.com/moby/sys/mountinfo/mountinfo_filters_test.go

Documentation: github.com/moby/sys/mountinfo

     1  package mountinfo
     2  
     3  import "testing"
     4  
     5  func TestPrefixFilter(t *testing.T) {
     6  	tests := []struct {
     7  		prefix     string
     8  		mountPoint string
     9  		shouldSkip bool
    10  	}{
    11  		{prefix: "/a", mountPoint: "/a", shouldSkip: false},
    12  		{prefix: "/a", mountPoint: "/a/b", shouldSkip: false},
    13  		{prefix: "/a", mountPoint: "/aa", shouldSkip: true},
    14  		{prefix: "/a", mountPoint: "/aa/b", shouldSkip: true},
    15  
    16  		// invalid prefix: prefix path must be cleaned and have no trailing slash
    17  		{prefix: "/a/", mountPoint: "/a", shouldSkip: true},
    18  		{prefix: "/a/", mountPoint: "/a/b", shouldSkip: true},
    19  	}
    20  	for _, tc := range tests {
    21  		filter := PrefixFilter(tc.prefix)
    22  		skip, _ := filter(&Info{Mountpoint: tc.mountPoint})
    23  		if skip != tc.shouldSkip {
    24  			if tc.shouldSkip {
    25  				t.Errorf("prefix %q: expected %q to be skipped", tc.prefix, tc.mountPoint)
    26  			} else {
    27  				t.Errorf("prefix %q: expected %q not to be skipped", tc.prefix, tc.mountPoint)
    28  			}
    29  		}
    30  	}
    31  }
    32  

View as plain text