Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
dbb448bb
Commit
dbb448bb
authored
May 30, 2018
by
fisherxu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move cacher in separate dir
parent
6cb344e7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
178 additions
and
130 deletions
+178
-130
storage_factory.go
...piserver/pkg/registry/generic/registry/storage_factory.go
+3
-2
store_test.go
....io/apiserver/pkg/registry/generic/registry/store_test.go
+3
-2
cacher.go
staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher.go
+40
-37
cacher_whitebox_test.go
...s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go
+1
-1
time_budget.go
...ng/src/k8s.io/apiserver/pkg/storage/cacher/time_budget.go
+1
-1
time_budget_test.go
...c/k8s.io/apiserver/pkg/storage/cacher/time_budget_test.go
+1
-1
util.go
staging/src/k8s.io/apiserver/pkg/storage/cacher/util.go
+46
-0
util_test.go
staging/src/k8s.io/apiserver/pkg/storage/cacher/util_test.go
+69
-0
watch_cache.go
...ng/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache.go
+4
-4
watch_cache_test.go
...c/k8s.io/apiserver/pkg/storage/cacher/watch_cache_test.go
+6
-5
cacher_test.go
...ing/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go
+4
-3
util.go
staging/src/k8s.io/apiserver/pkg/storage/util.go
+0
-26
util_test.go
staging/src/k8s.io/apiserver/pkg/storage/util_test.go
+0
-48
No files found.
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/storage_factory.go
View file @
dbb448bb
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage"
cacherstorage
"k8s.io/apiserver/pkg/storage/cacher"
etcdstorage
"k8s.io/apiserver/pkg/storage/etcd"
etcdstorage
"k8s.io/apiserver/pkg/storage/etcd"
"k8s.io/apiserver/pkg/storage/storagebackend"
"k8s.io/apiserver/pkg/storage/storagebackend"
"k8s.io/apiserver/pkg/storage/storagebackend/factory"
"k8s.io/apiserver/pkg/storage/storagebackend/factory"
...
@@ -49,7 +50,7 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
...
@@ -49,7 +50,7 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
// TODO: we would change this later to make storage always have cacher and hide low level KV layer inside.
// TODO: we would change this later to make storage always have cacher and hide low level KV layer inside.
// Currently it has two layers of same storage interface -- cacher and low level kv.
// Currently it has two layers of same storage interface -- cacher and low level kv.
cacherConfig
:=
storage
.
Cacher
Config
{
cacherConfig
:=
cacherstorage
.
Config
{
CacheCapacity
:
capacity
,
CacheCapacity
:
capacity
,
Storage
:
s
,
Storage
:
s
,
Versioner
:
etcdstorage
.
APIObjectVersioner
{},
Versioner
:
etcdstorage
.
APIObjectVersioner
{},
...
@@ -61,7 +62,7 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
...
@@ -61,7 +62,7 @@ func StorageWithCacher(capacity int) generic.StorageDecorator {
TriggerPublisherFunc
:
triggerFunc
,
TriggerPublisherFunc
:
triggerFunc
,
Codec
:
storageConfig
.
Codec
,
Codec
:
storageConfig
.
Codec
,
}
}
cacher
:=
storage
.
NewCacherFromConfig
(
cacherConfig
)
cacher
:=
cacher
storage
.
NewCacherFromConfig
(
cacherConfig
)
destroyFunc
:=
func
()
{
destroyFunc
:=
func
()
{
cacher
.
Stop
()
cacher
.
Stop
()
d
()
d
()
...
...
staging/src/k8s.io/apiserver/pkg/registry/generic/registry/store_test.go
View file @
dbb448bb
...
@@ -49,6 +49,7 @@ import (
...
@@ -49,6 +49,7 @@ import (
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/generic"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage"
cacherstorage
"k8s.io/apiserver/pkg/storage/cacher"
etcdstorage
"k8s.io/apiserver/pkg/storage/etcd"
etcdstorage
"k8s.io/apiserver/pkg/storage/etcd"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/apiserver/pkg/storage/names"
...
@@ -1849,7 +1850,7 @@ func newTestGenericStoreRegistry(t *testing.T, scheme *runtime.Scheme, hasCacheE
...
@@ -1849,7 +1850,7 @@ func newTestGenericStoreRegistry(t *testing.T, scheme *runtime.Scheme, hasCacheE
server
.
Terminate
(
t
)
server
.
Terminate
(
t
)
}
}
if
hasCacheEnabled
{
if
hasCacheEnabled
{
config
:=
storage
.
Cacher
Config
{
config
:=
cacherstorage
.
Config
{
CacheCapacity
:
10
,
CacheCapacity
:
10
,
Storage
:
s
,
Storage
:
s
,
Versioner
:
etcdstorage
.
APIObjectVersioner
{},
Versioner
:
etcdstorage
.
APIObjectVersioner
{},
...
@@ -1860,7 +1861,7 @@ func newTestGenericStoreRegistry(t *testing.T, scheme *runtime.Scheme, hasCacheE
...
@@ -1860,7 +1861,7 @@ func newTestGenericStoreRegistry(t *testing.T, scheme *runtime.Scheme, hasCacheE
NewListFunc
:
func
()
runtime
.
Object
{
return
&
example
.
PodList
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
example
.
PodList
{}
},
Codec
:
sc
.
Codec
,
Codec
:
sc
.
Codec
,
}
}
cacher
:=
storage
.
NewCacherFromConfig
(
config
)
cacher
:=
cacher
storage
.
NewCacherFromConfig
(
config
)
d
:=
destroyFunc
d
:=
destroyFunc
s
=
cacher
s
=
cacher
destroyFunc
=
func
()
{
destroyFunc
=
func
()
{
...
...
staging/src/k8s.io/apiserver/pkg/storage/cacher.go
→
staging/src/k8s.io/apiserver/pkg/storage/cacher
/cacher
.go
View file @
dbb448bb
This diff is collapsed.
Click to expand it.
staging/src/k8s.io/apiserver/pkg/storage/cacher_whitebox_test.go
→
staging/src/k8s.io/apiserver/pkg/storage/cacher
/cacher
_whitebox_test.go
View file @
dbb448bb
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
storage
package
cacher
import
(
import
(
"fmt"
"fmt"
...
...
staging/src/k8s.io/apiserver/pkg/storage/time_budget.go
→
staging/src/k8s.io/apiserver/pkg/storage/
cacher/
time_budget.go
View file @
dbb448bb
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
storage
package
cacher
import
(
import
(
"sync"
"sync"
...
...
staging/src/k8s.io/apiserver/pkg/storage/time_budget_test.go
→
staging/src/k8s.io/apiserver/pkg/storage/
cacher/
time_budget_test.go
View file @
dbb448bb
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
storage
package
cacher
import
(
import
(
"testing"
"testing"
...
...
staging/src/k8s.io/apiserver/pkg/storage/cacher/util.go
0 → 100644
View file @
dbb448bb
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
cacher
import
(
"strings"
)
// hasPathPrefix returns true if the string matches pathPrefix exactly, or if is prefixed with pathPrefix at a path segment boundary
func
hasPathPrefix
(
s
,
pathPrefix
string
)
bool
{
// Short circuit if s doesn't contain the prefix at all
if
!
strings
.
HasPrefix
(
s
,
pathPrefix
)
{
return
false
}
pathPrefixLength
:=
len
(
pathPrefix
)
if
len
(
s
)
==
pathPrefixLength
{
// Exact match
return
true
}
if
strings
.
HasSuffix
(
pathPrefix
,
"/"
)
{
// pathPrefix already ensured a path segment boundary
return
true
}
if
s
[
pathPrefixLength
:
pathPrefixLength
+
1
]
==
"/"
{
// The next character in s is a path segment boundary
// Check this instead of normalizing pathPrefix to avoid allocating on every call
return
true
}
return
false
}
staging/src/k8s.io/apiserver/pkg/storage/cacher/util_test.go
0 → 100644
View file @
dbb448bb
/*
Copyright 2015 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
cacher
import
(
"testing"
)
func
TestHasPathPrefix
(
t
*
testing
.
T
)
{
validTestcases
:=
[]
struct
{
s
string
prefix
string
}{
// Exact matches
{
""
,
""
},
{
"a"
,
"a"
},
{
"a/"
,
"a/"
},
{
"a/../"
,
"a/../"
},
// Path prefix matches
{
"a/b"
,
"a"
},
{
"a/b"
,
"a/"
},
{
"中文/"
,
"中文"
},
}
for
i
,
tc
:=
range
validTestcases
{
if
!
hasPathPrefix
(
tc
.
s
,
tc
.
prefix
)
{
t
.
Errorf
(
`%d: Expected hasPathPrefix("%s","%s") to be true`
,
i
,
tc
.
s
,
tc
.
prefix
)
}
}
invalidTestcases
:=
[]
struct
{
s
string
prefix
string
}{
// Mismatch
{
"a"
,
"b"
},
// Dir requirement
{
"a"
,
"a/"
},
// Prefix mismatch
{
"ns2"
,
"ns"
},
{
"ns2"
,
"ns/"
},
{
"中文文"
,
"中文"
},
// Ensure no normalization is applied
{
"a/c/../b/"
,
"a/b/"
},
{
"a/"
,
"a/b/.."
},
}
for
i
,
tc
:=
range
invalidTestcases
{
if
hasPathPrefix
(
tc
.
s
,
tc
.
prefix
)
{
t
.
Errorf
(
`%d: Expected hasPathPrefix("%s","%s") to be false`
,
i
,
tc
.
s
,
tc
.
prefix
)
}
}
}
staging/src/k8s.io/apiserver/pkg/storage/watch_cache.go
→
staging/src/k8s.io/apiserver/pkg/storage/
cacher/
watch_cache.go
View file @
dbb448bb
...
@@ -14,12 +14,11 @@ See the License for the specific language governing permissions and
...
@@ -14,12 +14,11 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
storage
package
cacher
import
(
import
(
"fmt"
"fmt"
"sort"
"sort"
"strconv"
"sync"
"sync"
"time"
"time"
...
@@ -29,6 +28,7 @@ import (
...
@@ -29,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apiserver/pkg/storage"
utiltrace
"k8s.io/apiserver/pkg/util/trace"
utiltrace
"k8s.io/apiserver/pkg/util/trace"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
)
)
...
@@ -138,14 +138,14 @@ type watchCache struct {
...
@@ -138,14 +138,14 @@ type watchCache struct {
clock
clock
.
Clock
clock
clock
.
Clock
// An underlying storage.Versioner.
// An underlying storage.Versioner.
versioner
Versioner
versioner
storage
.
Versioner
}
}
func
newWatchCache
(
func
newWatchCache
(
capacity
int
,
capacity
int
,
keyFunc
func
(
runtime
.
Object
)
(
string
,
error
),
keyFunc
func
(
runtime
.
Object
)
(
string
,
error
),
getAttrsFunc
func
(
runtime
.
Object
)
(
labels
.
Set
,
fields
.
Set
,
bool
,
error
),
getAttrsFunc
func
(
runtime
.
Object
)
(
labels
.
Set
,
fields
.
Set
,
bool
,
error
),
versioner
Versioner
)
*
watchCache
{
versioner
storage
.
Versioner
)
*
watchCache
{
wc
:=
&
watchCache
{
wc
:=
&
watchCache
{
capacity
:
capacity
,
capacity
:
capacity
,
keyFunc
:
keyFunc
,
keyFunc
:
keyFunc
,
...
...
staging/src/k8s.io/apiserver/pkg/storage/watch_cache_test.go
→
staging/src/k8s.io/apiserver/pkg/storage/
cacher/
watch_cache_test.go
View file @
dbb448bb
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
...
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
*/
*/
package
storage
package
cacher
import
(
import
(
"fmt"
"fmt"
...
@@ -32,7 +32,8 @@ import (
...
@@ -32,7 +32,8 @@ import (
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/clock"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/apimachinery/pkg/watch"
etcdstorage
"k8s.io/apiserver/pkg/storage/etcd"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage/etcd"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/cache"
)
)
...
@@ -65,16 +66,16 @@ func makeTestStoreElement(pod *v1.Pod) *storeElement {
...
@@ -65,16 +66,16 @@ func makeTestStoreElement(pod *v1.Pod) *storeElement {
// newTestWatchCache just adds a fake clock.
// newTestWatchCache just adds a fake clock.
func
newTestWatchCache
(
capacity
int
)
*
watchCache
{
func
newTestWatchCache
(
capacity
int
)
*
watchCache
{
keyFunc
:=
func
(
obj
runtime
.
Object
)
(
string
,
error
)
{
keyFunc
:=
func
(
obj
runtime
.
Object
)
(
string
,
error
)
{
return
NamespaceKeyFunc
(
"prefix"
,
obj
)
return
storage
.
NamespaceKeyFunc
(
"prefix"
,
obj
)
}
}
getAttrsFunc
:=
func
(
obj
runtime
.
Object
)
(
labels
.
Set
,
fields
.
Set
,
bool
,
error
)
{
getAttrsFunc
:=
func
(
obj
runtime
.
Object
)
(
labels
.
Set
,
fields
.
Set
,
bool
,
error
)
{
pod
,
ok
:=
obj
.
(
*
v1
.
Pod
)
pod
,
ok
:=
obj
.
(
*
v1
.
Pod
)
if
!
ok
{
if
!
ok
{
return
nil
,
nil
,
false
,
fmt
.
Errorf
(
"not a pod
!
"
)
return
nil
,
nil
,
false
,
fmt
.
Errorf
(
"not a pod"
)
}
}
return
labels
.
Set
(
pod
.
Labels
),
fields
.
Set
{
"spec.nodeName"
:
pod
.
Spec
.
NodeName
},
false
,
nil
return
labels
.
Set
(
pod
.
Labels
),
fields
.
Set
{
"spec.nodeName"
:
pod
.
Spec
.
NodeName
},
false
,
nil
}
}
versioner
:=
etcd
storage
.
APIObjectVersioner
{}
versioner
:=
etcd
.
APIObjectVersioner
{}
wc
:=
newWatchCache
(
capacity
,
keyFunc
,
getAttrsFunc
,
versioner
)
wc
:=
newWatchCache
(
capacity
,
keyFunc
,
getAttrsFunc
,
versioner
)
wc
.
clock
=
clock
.
NewFakeClock
(
time
.
Now
())
wc
.
clock
=
clock
.
NewFakeClock
(
time
.
Now
())
return
wc
return
wc
...
...
staging/src/k8s.io/apiserver/pkg/storage/tests/cacher_test.go
View file @
dbb448bb
...
@@ -40,6 +40,7 @@ import (
...
@@ -40,6 +40,7 @@ import (
"k8s.io/apiserver/pkg/apis/example"
"k8s.io/apiserver/pkg/apis/example"
examplev1
"k8s.io/apiserver/pkg/apis/example/v1"
examplev1
"k8s.io/apiserver/pkg/apis/example/v1"
"k8s.io/apiserver/pkg/storage"
"k8s.io/apiserver/pkg/storage"
cacherstorage
"k8s.io/apiserver/pkg/storage/cacher"
etcdstorage
"k8s.io/apiserver/pkg/storage/etcd"
etcdstorage
"k8s.io/apiserver/pkg/storage/etcd"
"k8s.io/apiserver/pkg/storage/etcd/etcdtest"
"k8s.io/apiserver/pkg/storage/etcd/etcdtest"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
etcdtesting
"k8s.io/apiserver/pkg/storage/etcd/testing"
...
@@ -95,10 +96,10 @@ func newEtcdTestStorage(t *testing.T, prefix string) (*etcdtesting.EtcdTestServe
...
@@ -95,10 +96,10 @@ func newEtcdTestStorage(t *testing.T, prefix string) (*etcdtesting.EtcdTestServe
return
server
,
storage
return
server
,
storage
}
}
func
newTestCacher
(
s
storage
.
Interface
,
cap
int
)
(
*
storage
.
Cacher
,
storage
.
Versioner
)
{
func
newTestCacher
(
s
storage
.
Interface
,
cap
int
)
(
*
cacher
storage
.
Cacher
,
storage
.
Versioner
)
{
prefix
:=
"pods"
prefix
:=
"pods"
v
:=
etcdstorage
.
APIObjectVersioner
{}
v
:=
etcdstorage
.
APIObjectVersioner
{}
config
:=
storage
.
Cacher
Config
{
config
:=
cacherstorage
.
Config
{
CacheCapacity
:
cap
,
CacheCapacity
:
cap
,
Storage
:
s
,
Storage
:
s
,
Versioner
:
v
,
Versioner
:
v
,
...
@@ -109,7 +110,7 @@ func newTestCacher(s storage.Interface, cap int) (*storage.Cacher, storage.Versi
...
@@ -109,7 +110,7 @@ func newTestCacher(s storage.Interface, cap int) (*storage.Cacher, storage.Versi
NewListFunc
:
func
()
runtime
.
Object
{
return
&
example
.
PodList
{}
},
NewListFunc
:
func
()
runtime
.
Object
{
return
&
example
.
PodList
{}
},
Codec
:
codecs
.
LegacyCodec
(
examplev1
.
SchemeGroupVersion
),
Codec
:
codecs
.
LegacyCodec
(
examplev1
.
SchemeGroupVersion
),
}
}
return
storage
.
NewCacherFromConfig
(
config
),
v
return
cacher
storage
.
NewCacherFromConfig
(
config
),
v
}
}
func
makeTestPod
(
name
string
)
*
example
.
Pod
{
func
makeTestPod
(
name
string
)
*
example
.
Pod
{
...
...
staging/src/k8s.io/apiserver/pkg/storage/util.go
View file @
dbb448bb
...
@@ -18,7 +18,6 @@ package storage
...
@@ -18,7 +18,6 @@ package storage
import
(
import
(
"fmt"
"fmt"
"strings"
"sync/atomic"
"sync/atomic"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/meta"
...
@@ -72,31 +71,6 @@ func NoNamespaceKeyFunc(prefix string, obj runtime.Object) (string, error) {
...
@@ -72,31 +71,6 @@ func NoNamespaceKeyFunc(prefix string, obj runtime.Object) (string, error) {
return
prefix
+
"/"
+
name
,
nil
return
prefix
+
"/"
+
name
,
nil
}
}
// hasPathPrefix returns true if the string matches pathPrefix exactly, or if is prefixed with pathPrefix at a path segment boundary
func
hasPathPrefix
(
s
,
pathPrefix
string
)
bool
{
// Short circuit if s doesn't contain the prefix at all
if
!
strings
.
HasPrefix
(
s
,
pathPrefix
)
{
return
false
}
pathPrefixLength
:=
len
(
pathPrefix
)
if
len
(
s
)
==
pathPrefixLength
{
// Exact match
return
true
}
if
strings
.
HasSuffix
(
pathPrefix
,
"/"
)
{
// pathPrefix already ensured a path segment boundary
return
true
}
if
s
[
pathPrefixLength
:
pathPrefixLength
+
1
]
==
"/"
{
// The next character in s is a path segment boundary
// Check this instead of normalizing pathPrefix to avoid allocating on every call
return
true
}
return
false
}
// HighWaterMark is a thread-safe object for tracking the maximum value seen
// HighWaterMark is a thread-safe object for tracking the maximum value seen
// for some quantity.
// for some quantity.
type
HighWaterMark
int64
type
HighWaterMark
int64
...
...
staging/src/k8s.io/apiserver/pkg/storage/util_test.go
View file @
dbb448bb
...
@@ -22,54 +22,6 @@ import (
...
@@ -22,54 +22,6 @@ import (
"testing"
"testing"
)
)
func
TestHasPathPrefix
(
t
*
testing
.
T
)
{
validTestcases
:=
[]
struct
{
s
string
prefix
string
}{
// Exact matches
{
""
,
""
},
{
"a"
,
"a"
},
{
"a/"
,
"a/"
},
{
"a/../"
,
"a/../"
},
// Path prefix matches
{
"a/b"
,
"a"
},
{
"a/b"
,
"a/"
},
{
"中文/"
,
"中文"
},
}
for
i
,
tc
:=
range
validTestcases
{
if
!
hasPathPrefix
(
tc
.
s
,
tc
.
prefix
)
{
t
.
Errorf
(
`%d: Expected hasPathPrefix("%s","%s") to be true`
,
i
,
tc
.
s
,
tc
.
prefix
)
}
}
invalidTestcases
:=
[]
struct
{
s
string
prefix
string
}{
// Mismatch
{
"a"
,
"b"
},
// Dir requirement
{
"a"
,
"a/"
},
// Prefix mismatch
{
"ns2"
,
"ns"
},
{
"ns2"
,
"ns/"
},
{
"中文文"
,
"中文"
},
// Ensure no normalization is applied
{
"a/c/../b/"
,
"a/b/"
},
{
"a/"
,
"a/b/.."
},
}
for
i
,
tc
:=
range
invalidTestcases
{
if
hasPathPrefix
(
tc
.
s
,
tc
.
prefix
)
{
t
.
Errorf
(
`%d: Expected hasPathPrefix("%s","%s") to be false`
,
i
,
tc
.
s
,
tc
.
prefix
)
}
}
}
func
TestHighWaterMark
(
t
*
testing
.
T
)
{
func
TestHighWaterMark
(
t
*
testing
.
T
)
{
var
h
HighWaterMark
var
h
HighWaterMark
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment