mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-29 14:41:09 +01:00
Exit ScanView if context has been cancelled (#7419)
This commit is contained in:
parent
6c54c27ac0
commit
33fd94e56f
@ -74,6 +74,10 @@ func ScanView(ctx context.Context, view ClearableView, cb func(path string)) err
|
|||||||
|
|
||||||
// Handle the contents in the directory
|
// Handle the contents in the directory
|
||||||
for _, c := range contents {
|
for _, c := range contents {
|
||||||
|
// Exit if the context has been canceled
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
return ctx.Err()
|
||||||
|
}
|
||||||
fullPath := current + c
|
fullPath := current + c
|
||||||
if strings.HasSuffix(c, "/") {
|
if strings.HasSuffix(c, "/") {
|
||||||
frontier = append(frontier, fullPath)
|
frontier = append(frontier, fullPath)
|
||||||
|
|||||||
@ -34,6 +34,24 @@ func TestScanView(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestScanView_CancelContext(t *testing.T) {
|
||||||
|
s := prepKeyStorage(t)
|
||||||
|
|
||||||
|
ctx, cancelCtx := context.WithCancel(context.Background())
|
||||||
|
var i int
|
||||||
|
err := ScanView(ctx, s, func(path string) {
|
||||||
|
cancelCtx()
|
||||||
|
i++
|
||||||
|
})
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Want context cancel err, got none")
|
||||||
|
}
|
||||||
|
if i != 1 {
|
||||||
|
t.Errorf("Want i==1, got %d", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestCollectKeys(t *testing.T) {
|
func TestCollectKeys(t *testing.T) {
|
||||||
s := prepKeyStorage(t)
|
s := prepKeyStorage(t)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user