MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / TestMemLSCanCreate

Function TestMemLSCanCreate

server/webdav/lock_test.go:98–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

96}
97
98func TestMemLSCanCreate(t *testing.T) {
99 now := time.Unix(0, 0)
100 m := NewMemLS().(*memLS)
101
102 for _, name := range lockTestNames {
103 _, err := m.Create(now, LockDetails{
104 Root: name,
105 Duration: infiniteTimeout,
106 ZeroDepth: lockTestZeroDepth(name),
107 })
108 if err != nil {
109 t.Fatalf("creating lock for %q: %v", name, err)
110 }
111 }
112
113 wantCanCreate := func(name string, zeroDepth bool) bool {
114 for _, n := range lockTestNames {
115 switch {
116 case n == name:
117 // An existing lock has the same name as the proposed lock.
118 return false
119 case strings.HasPrefix(n, name):
120 // An existing lock would be a child of the proposed lock,
121 // which conflicts if the proposed lock has infinite depth.
122 if !zeroDepth {
123 return false
124 }
125 case strings.HasPrefix(name, n):
126 // An existing lock would be an ancestor of the proposed lock,
127 // which conflicts if the ancestor has infinite depth.
128 if n[len(n)-1] == 'i' {
129 return false
130 }
131 }
132 }
133 return true
134 }
135
136 var check func(int, string)
137 check = func(recursion int, name string) {
138 for _, zeroDepth := range []bool{false, true} {
139 got := m.canCreate(name, zeroDepth)
140 want := wantCanCreate(name, zeroDepth)
141 if got != want {
142 t.Errorf("canCreate name=%q zeroDepth=%t: got %t, want %t", name, zeroDepth, got, want)
143 }
144 }
145 if recursion == 6 {
146 return
147 }
148 if name != "/" {
149 name += "/"
150 }
151 for _, c := range "_iz" {
152 check(recursion+1, name+string(c))
153 }
154 }
155 check(0, "/")

Callers

nothing calls this directly

Calls 4

NewMemLSFunction · 0.85
lockTestZeroDepthFunction · 0.85
canCreateMethod · 0.80
CreateMethod · 0.65

Tested by

no test coverage detected