@@ -26,6 +26,69 @@ func AdapterTest(t *testing.T, adapter block.Adapter, storageNamespace, external
2626 t .Run ("Adapter_Exists" , func (t * testing.T ) { testAdapterExists (t , adapter , storageNamespace ) })
2727 t .Run ("Adapter_GetRange" , func (t * testing.T ) { testAdapterGetRange (t , adapter , storageNamespace ) })
2828 t .Run ("Adapter_Walker" , func (t * testing.T ) { testAdapterWalker (t , adapter , storageNamespace ) })
29+ t .Run ("Adapter_Clean" , func (t * testing.T ) { testAdapterClean (t , adapter , storageNamespace ) })
30+ }
31+
32+ func testAdapterClean (t * testing.T , adapter block.Adapter , storageNamespace string ) { //nolint
33+ ctx := context .Background ()
34+ const content = "content used for testing"
35+
36+ tests := []struct {
37+ name string
38+ additionalObjects []string
39+ path string
40+ wantErr bool
41+ wantTree []string
42+ }{
43+ {
44+ name : "test_single" ,
45+ path : "README" ,
46+ wantErr : false ,
47+ wantTree : []string {},
48+ },
49+
50+ {
51+ name : "test_under_folder" ,
52+ path : "src/tools.go" ,
53+ wantErr : false ,
54+ wantTree : []string {},
55+ },
56+ {
57+ name : "test_under_multiple_folders" ,
58+ path : "a/b/c/d.txt" ,
59+ wantErr : false ,
60+ wantTree : []string {},
61+ },
62+ {
63+ name : "file_in_the_way" ,
64+ path : "a/b/c/d.txt" ,
65+ additionalObjects : []string {"a/b/blocker.txt" },
66+ wantErr : false ,
67+ wantTree : []string {"/a/b/blocker.txt" },
68+ },
69+ }
70+
71+ // setup env
72+ for _ , tt := range tests {
73+ t .Run (tt .name , func (t * testing.T ) {
74+ envObjects := tt .additionalObjects
75+ envObjects = append (envObjects , tt .path )
76+ for _ , p := range envObjects {
77+ obj := block.ObjectPointer {
78+ StorageNamespace : storageNamespace ,
79+ Identifier : tt .name + "/" + p ,
80+ IdentifierType : block .IdentifierTypeRelative ,
81+ }
82+ require .NoError (t , adapter .Put (ctx , obj , int64 (len (content )), strings .NewReader (content ), block.PutOpts {}))
83+ }
84+ })
85+ }
86+
87+ // clean
88+ t .Run ("clean repo" , func (t * testing.T ) {
89+ err := adapter .RemoveNameSpace (ctx , storageNamespace )
90+ require .NoError (t , err )
91+ })
2992}
3093
3194func testAdapterPutGet (t * testing.T , adapter block.Adapter , storageNamespace , externalPath string ) {
0 commit comments