File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -182,3 +182,10 @@ func Capabilities(fs Basic) Capability {
182
182
183
183
return capable .Capabilities ()
184
184
}
185
+
186
+ // CapabilityCheck tests the filesystem for the provided capabilities and
187
+ // returns true in case it supports all of them.
188
+ func CapabilityCheck (fs Basic , capabilities Capability ) bool {
189
+ fsCaps := Capabilities (fs )
190
+ return fsCaps & capabilities == capabilities
191
+ }
Original file line number Diff line number Diff line change
1
+ package billy_test
2
+
3
+ import (
4
+ "testing"
5
+
6
+ . "gopkg.in/src-d/go-billy.v4"
7
+ "gopkg.in/src-d/go-billy.v4/memfs"
8
+
9
+ . "gopkg.in/check.v1"
10
+ )
11
+
12
+ type FSSuite struct {}
13
+
14
+ func Test (t * testing.T ) { TestingT (t ) }
15
+
16
+ var _ = Suite (& FSSuite {})
17
+
18
+ func (s * FSSuite ) TestCapabilities (c * C ) {
19
+ cases := []struct {
20
+ caps Capability
21
+ expected bool
22
+ }{
23
+ {CapLock , false },
24
+ {CapRead , true },
25
+ {CapRead | CapWrite , true },
26
+ {CapRead | CapWrite | CapReadAndWrite | CapTruncate , true },
27
+ {CapRead | CapWrite | CapReadAndWrite | CapTruncate | CapLock , false },
28
+ {CapTruncate | CapLock , false },
29
+ }
30
+
31
+ // This filesystem supports all capabilities except for CapLock
32
+ mem := memfs .New ()
33
+
34
+ for _ , e := range cases {
35
+ c .Assert (CapabilityCheck (mem , e .caps ), Equals , e .expected )
36
+ }
37
+ }
You can’t perform that action at this time.
0 commit comments