@@ -2,6 +2,7 @@ package bloomshipper
2
2
3
3
import (
4
4
"context"
5
+ "io/fs"
5
6
"os"
6
7
"path/filepath"
7
8
"sync"
@@ -66,19 +67,24 @@ func Test_LoadBlocksDirIntoCache(t *testing.T) {
66
67
fp .Close ()
67
68
68
69
// invalid directory
69
- _ = os .MkdirAll (filepath .Join (wd , "not/a/valid/blockdir" ), 0o755 )
70
+ invalidDir := "not/a/valid/blockdir"
71
+ _ = os .MkdirAll (filepath .Join (wd , invalidDir ), 0o755 )
70
72
71
- // empty block directory
72
- fn1 := "bloom/table_1/tenant/blocks/0000000000000000-000000000000ffff/0-3600000-abcd"
73
- _ = os .MkdirAll (filepath .Join (wd , fn1 ), 0o755 )
73
+ // empty block directories
74
+ emptyDir1 := "bloom/table_1/tenant/blocks/0000000000000000-000000000000ffff/0-3600000-abcd"
75
+ _ = os .MkdirAll (filepath .Join (wd , emptyDir1 ), 0o755 )
76
+ emptyDir2 := "bloom/table_1/tenant/blocks/0000000000010000-000000000001ffff/0-3600000-ef01"
77
+ _ = os .MkdirAll (filepath .Join (wd , emptyDir2 ), 0o755 )
78
+ emptyDir3 := "bloom/table_1/tenant/blocks/0000000000020000-000000000002ffff/0-3600000-2345"
79
+ _ = os .MkdirAll (filepath .Join (wd , emptyDir3 ), 0o755 )
74
80
75
81
// valid block directory
76
- fn2 := "bloom/table_2/tenant/blocks/0000000000010000-000000000001ffff/0-3600000-abcd"
77
- _ = os .MkdirAll (filepath .Join (wd , fn2 ), 0o755 )
78
- fp , _ = os . Create ( filepath . Join ( wd , fn2 , "bloom" ))
79
- fp . Close ( )
80
- fp , _ = os . Create ( filepath . Join ( wd , fn2 , "series" ) )
81
- fp . Close ()
82
+ validDir := "bloom/table_2/tenant/blocks/0000000000010000-000000000001ffff/0-3600000-abcd"
83
+ _ = os .MkdirAll (filepath .Join (wd , validDir ), 0o755 )
84
+ for _ , fn := range [] string { "bloom" , "series" } {
85
+ fp , _ = os . Create ( filepath . Join ( wd , validDir , fn ) )
86
+ fp . Close ( )
87
+ }
82
88
83
89
cfg := config.BlocksCacheConfig {
84
90
SoftLimit : 1 << 20 ,
@@ -93,9 +99,28 @@ func Test_LoadBlocksDirIntoCache(t *testing.T) {
93
99
94
100
require .Equal (t , 1 , len (c .entries ))
95
101
96
- key := filepath .Join (wd , fn2 ) + ".tar.gz"
102
+ key := filepath .Join (wd , validDir ) + ".tar.gz"
97
103
elem , found := c .entries [key ]
98
104
require .True (t , found )
99
105
blockDir := elem .Value .(* Entry ).Value
100
- require .Equal (t , filepath .Join (wd , fn2 ), blockDir .Path )
106
+ require .Equal (t , filepath .Join (wd , validDir ), blockDir .Path )
107
+
108
+ // check cleaned directories
109
+ dirs := make ([]string , 0 , 6 )
110
+ _ = filepath .WalkDir (wd , func (path string , dirEntry fs.DirEntry , _ error ) error {
111
+ if ! dirEntry .IsDir () {
112
+ return nil
113
+ }
114
+ dirs = append (dirs , path )
115
+ return nil
116
+ })
117
+ require .Equal (t , []string {
118
+ filepath .Join (wd ),
119
+ filepath .Join (wd , "bloom/" ),
120
+ filepath .Join (wd , "bloom/table_2/" ),
121
+ filepath .Join (wd , "bloom/table_2/tenant/" ),
122
+ filepath .Join (wd , "bloom/table_2/tenant/blocks/" ),
123
+ filepath .Join (wd , "bloom/table_2/tenant/blocks/0000000000010000-000000000001ffff" ),
124
+ filepath .Join (wd , "bloom/table_2/tenant/blocks/0000000000010000-000000000001ffff/0-3600000-abcd" ),
125
+ }, dirs )
101
126
}
0 commit comments