Skip to content

Commit ab36809

Browse files
authored
test(operations): bifurcate write operations for rapid writes flagsets (#4983)
1 parent 977d58b commit ab36809

21 files changed

Lines changed: 650 additions & 503 deletions

tools/integration_tests/operations/copy_dir_test.go

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,29 @@ import (
1919
"log"
2020
"os"
2121
"path"
22-
"testing"
2322

2423
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/operations"
2524
"github.com/googlecloudplatform/gcsfuse/v3/tools/integration_tests/util/setup"
25+
"github.com/stretchr/testify/require"
2626
)
2727

2828
// Create below directory structure.
2929
// srcCopyDir -- Dir
3030
// srcCopyDir/copy.txt -- File
3131
// srcCopyDir/subSrcCopyDir -- Dir
32-
func createSrcDirectoryWithObjects(dirPath string, t *testing.T) string {
32+
func (s *operationsTestSuite) createSrcDirectoryWithObjects(dirPath string) string {
3333
// testBucket/srcCopyDir
3434
err := os.Mkdir(dirPath, setup.FilePermission_0600)
3535
if err != nil {
36-
t.Errorf("Mkdir at %q: %v", dirPath, err)
36+
s.T().Errorf("Mkdir at %q: %v", dirPath, err)
3737
return ""
3838
}
3939

4040
// testBucket/subSrcCopyDir
4141
subDirPath := path.Join(dirPath, SubSrcCopyDirectory)
4242
err = os.Mkdir(subDirPath, setup.FilePermission_0600)
4343
if err != nil {
44-
t.Errorf("Mkdir at %q: %v", subDirPath, err)
44+
s.T().Errorf("Mkdir at %q: %v", subDirPath, err)
4545
return ""
4646
}
4747

@@ -50,52 +50,52 @@ func createSrcDirectoryWithObjects(dirPath string, t *testing.T) string {
5050

5151
file, err := os.Create(filePath)
5252
if err != nil {
53-
t.Errorf("Error in creating file %v:", err)
53+
s.T().Errorf("Error in creating file %v:", err)
5454
}
5555

5656
err = operations.WriteFile(file.Name(), SrcCopyFileContent)
5757
if err != nil {
58-
t.Errorf("File at %v", err)
58+
s.T().Errorf("File at %v", err)
5959
}
6060

6161
// Closing file at the end
62-
defer operations.CloseFileShouldNotThrowError(t, file)
62+
defer operations.CloseFileShouldNotThrowError(s.T(), file)
6363

6464
return dirPath
6565
}
6666

67-
func checkIfCopiedDirectoryHasCorrectData(destDir string, t *testing.T) {
67+
func (s *operationsTestSuite) checkIfCopiedDirectoryHasCorrectData(destDir string) {
6868
obj, err := os.ReadDir(destDir)
6969
if err != nil {
7070
log.Fatal(err)
7171
}
7272

7373
// Comparing number of objects in the testBucket - 2
7474
if len(obj) != NumberOfObjectsInSrcCopyDirectory {
75-
t.Errorf("The number of objects in the current directory doesn't match.")
75+
s.T().Errorf("The number of objects in the current directory doesn't match.")
7676
return
7777
}
7878

7979
// Comparing first object name and type
8080
// Name - testBucket/destCopyDir/copy.txt, Type - file
8181
if obj[0].Name() != SrcCopyFile || obj[0].IsDir() == true {
82-
t.Errorf("Object Listed for bucket directory is incorrect.")
82+
s.T().Errorf("Object Listed for bucket directory is incorrect.")
8383
}
8484

8585
// Comparing second object name and type
8686
// Name - testBucket/destCopyDir/srcCopyDir, Type - dir
8787
if obj[1].Name() != SubSrcCopyDirectory || obj[1].IsDir() != true {
88-
t.Errorf("Object Listed for bucket directory is incorrect.")
88+
s.T().Errorf("Object Listed for bucket directory is incorrect.")
8989
}
9090

9191
destFile := path.Join(destDir, SrcCopyFile)
9292

9393
content, err := operations.ReadFile(destFile)
9494
if err != nil {
95-
t.Errorf("ReadAll: %v", err)
95+
s.T().Errorf("ReadAll: %v", err)
9696
}
9797
if got, want := string(content), SrcCopyFileContent; got != want {
98-
t.Errorf("File content %q not match %q", got, want)
98+
s.T().Errorf("File content %q not match %q", got, want)
9999
}
100100
}
101101

@@ -107,17 +107,15 @@ func checkIfCopiedDirectoryHasCorrectData(destDir string, t *testing.T) {
107107
// destCopyDir -- Dir
108108
// destCopyDir/copy.txt -- File
109109
// destCopyDir/subSrcCopyDir -- Dir
110-
func TestCopyDirectoryInNonExistingDirectory(t *testing.T) {
110+
func (s *operationsTestSuite) TestCopyDirectoryInNonExistingDirectory() {
111111
testDir := setup.SetupTestDirectory(DirForOperationTests)
112-
srcDir := createSrcDirectoryWithObjects(path.Join(testDir, SrcCopyDirectory), t)
112+
srcDir := s.createSrcDirectoryWithObjects(path.Join(testDir, SrcCopyDirectory))
113113
destDir := path.Join(testDir, DestCopyDirectoryNotExist)
114114

115115
err := operations.CopyDir(srcDir, destDir)
116-
if err != nil {
117-
t.Errorf("Error in copying directory: %v", err)
118-
}
116+
require.NoError(s.T(), err, "Error in copying directory")
119117

120-
checkIfCopiedDirectoryHasCorrectData(destDir, t)
118+
s.checkIfCopiedDirectoryHasCorrectData(destDir)
121119
}
122120

123121
// Copy SrcDirectory in DestDirectory
@@ -129,22 +127,20 @@ func TestCopyDirectoryInNonExistingDirectory(t *testing.T) {
129127
// destCopyDir/srcCopyDir -- Dir
130128
// destCopyDir/srcCopyDir/copy.txt -- File
131129
// destCopyDir/srcCopyDir/subSrcCopyDir -- Dir
132-
func TestCopyDirectoryInEmptyDirectory(t *testing.T) {
130+
func (s *operationsTestSuite) TestCopyDirectoryInEmptyDirectory() {
133131
testDir := setup.SetupTestDirectory(DirForOperationTests)
134-
srcDir := createSrcDirectoryWithObjects(path.Join(testDir, SrcCopyDirectory), t)
132+
srcDir := s.createSrcDirectoryWithObjects(path.Join(testDir, SrcCopyDirectory))
135133

136134
// Create below directory
137135
// destCopyDir -- Dir
138136
destDir := path.Join(testDir, DestCopyDirectory)
139137
err := os.Mkdir(destDir, setup.FilePermission_0600)
140138
if err != nil {
141-
t.Errorf("Error in creating directory: %v", err)
139+
s.T().Errorf("Error in creating directory: %v", err)
142140
}
143141

144142
err = operations.CopyDir(srcDir, destDir)
145-
if err != nil {
146-
t.Errorf("Error in copying directory: %v", err)
147-
}
143+
require.NoError(s.T(), err, "Error in copying directory")
148144

149145
obj, err := os.ReadDir(destDir)
150146
if err != nil {
@@ -155,35 +151,33 @@ func TestCopyDirectoryInEmptyDirectory(t *testing.T) {
155151
// destCopyDirectory
156152
// destCopyDirectory/srcCopyDirectory
157153
if len(obj) != 1 || obj[0].Name() != SrcCopyDirectory || obj[0].IsDir() != true {
158-
t.Errorf("Error in copying directory.")
154+
s.T().Errorf("Error in copying directory.")
159155
return
160156
}
161157

162158
destSrc := path.Join(destDir, SrcCopyDirectory)
163-
checkIfCopiedDirectoryHasCorrectData(destSrc, t)
159+
s.checkIfCopiedDirectoryHasCorrectData(destSrc)
164160
}
165161

166-
func createDestNonEmptyDirectory(dirPath string, t *testing.T) string {
167-
operations.CreateDirectoryWithNFiles(0, dirPath, "", t)
162+
func (s *operationsTestSuite) createDestNonEmptyDirectory(dirPath string) string {
163+
operations.CreateDirectoryWithNFiles(0, dirPath, "", s.T())
168164

169165
destSubDir := path.Join(dirPath, SubDirInNonEmptyDestCopyDirectory)
170-
operations.CreateDirectoryWithNFiles(0, destSubDir, "", t)
166+
operations.CreateDirectoryWithNFiles(0, destSubDir, "", s.T())
171167

172168
return dirPath
173169
}
174170

175-
func TestCopyDirectoryInNonEmptyDirectory(t *testing.T) {
171+
func (s *operationsTestSuite) TestCopyDirectoryInNonEmptyDirectory() {
176172
testDir := setup.SetupTestDirectory(DirForOperationTests)
177-
srcDir := createSrcDirectoryWithObjects(path.Join(testDir, SrcCopyDirectory), t)
173+
srcDir := s.createSrcDirectoryWithObjects(path.Join(testDir, SrcCopyDirectory))
178174

179175
// Create below directory
180176
// destCopyDir -- Dir
181-
destDir := createDestNonEmptyDirectory(path.Join(testDir, DestNonEmptyCopyDirectory), t)
177+
destDir := s.createDestNonEmptyDirectory(path.Join(testDir, DestNonEmptyCopyDirectory))
182178

183179
err := operations.CopyDir(srcDir, destDir)
184-
if err != nil {
185-
t.Errorf("Error in copying directory: %v", err)
186-
}
180+
require.NoError(s.T(), err, "Error in copying directory")
187181

188182
obj, err := os.ReadDir(destDir)
189183
if err != nil {
@@ -195,34 +189,34 @@ func TestCopyDirectoryInNonEmptyDirectory(t *testing.T) {
195189
// destCopyDirectory/srcCopyDirectory
196190
// destCopyDirectory/subDestCopyDirectory
197191
if len(obj) != NumberOfObjectsInNonEmptyDestCopyDirectory {
198-
t.Errorf("The number of objects in the current directory doesn't match.")
192+
s.T().Errorf("The number of objects in the current directory doesn't match.")
199193
return
200194
}
201195

202196
// destCopyDirectory/srcCopyDirectory - Dir
203197
if obj[0].Name() != SrcCopyDirectory || obj[0].IsDir() != true {
204-
t.Errorf("Error in copying directory.")
198+
s.T().Errorf("Error in copying directory.")
205199
return
206200
}
207201

208202
// destCopyDirectory/subDirInNonEmptyDestCopyDirectory - Dir
209203
if obj[1].Name() != SubDirInNonEmptyDestCopyDirectory || obj[1].IsDir() != true {
210-
t.Errorf("Existing object affected.")
204+
s.T().Errorf("Existing object affected.")
211205
return
212206
}
213207

214208
destSrc := path.Join(destDir, SrcCopyDirectory)
215-
checkIfCopiedDirectoryHasCorrectData(destSrc, t)
209+
s.checkIfCopiedDirectoryHasCorrectData(destSrc)
216210
}
217211

218-
func checkIfCopiedEmptyDirectoryHasNoData(destSrc string, t *testing.T) {
212+
func (s *operationsTestSuite) checkIfCopiedEmptyDirectoryHasNoData(destSrc string) {
219213
objs, err := os.ReadDir(destSrc)
220214
if err != nil {
221215
log.Fatal(err)
222216
}
223217

224218
if len(objs) != 0 {
225-
t.Errorf("Directory has incorrect data.")
219+
s.T().Errorf("Directory has incorrect data.")
226220
}
227221
}
228222

@@ -236,21 +230,19 @@ func checkIfCopiedEmptyDirectoryHasNoData(destSrc string, t *testing.T) {
236230
// destNonEmptyCopyDirectory
237231
// destNonEmptyCopyDirectory/subDirInNonEmptyDestCopyDirectory
238232
// destNonEmptyCopyDirectory/emptySrcDirectoryCopyTest
239-
func TestCopyEmptyDirectoryInNonEmptyDirectory(t *testing.T) {
233+
func (s *operationsTestSuite) TestCopyEmptyDirectoryInNonEmptyDirectory() {
240234
testDir := setup.SetupTestDirectory(DirForOperationTests)
241235

242236
srcDir := path.Join(testDir, EmptySrcDirectoryCopyTest)
243-
operations.CreateDirectoryWithNFiles(0, srcDir, "", t)
237+
operations.CreateDirectoryWithNFiles(0, srcDir, "", s.T())
244238

245239
// Create below directory
246240
// destNonEmptyCopyDirectory -- Dir
247241
// destNonEmptyCopyDirectory/subDirInNonEmptyDestCopyDirectory -- Dir
248-
destDir := createDestNonEmptyDirectory(path.Join(testDir, DestNonEmptyCopyDirectory), t)
242+
destDir := s.createDestNonEmptyDirectory(path.Join(testDir, DestNonEmptyCopyDirectory))
249243

250244
err := operations.CopyDir(srcDir, destDir)
251-
if err != nil {
252-
t.Errorf("Error in copying directory: %v", err)
253-
}
245+
require.NoError(s.T(), err, "Error in copying directory")
254246

255247
objs, err := os.ReadDir(destDir)
256248
if err != nil {
@@ -262,24 +254,24 @@ func TestCopyEmptyDirectoryInNonEmptyDirectory(t *testing.T) {
262254
// destNonEmptyCopyDirectory/emptyDirectoryCopyTest - Dir
263255
// destNonEmptyCopyDirectory/subDestCopyDirectory - Dir
264256
if len(objs) != NumberOfObjectsInNonEmptyDestCopyDirectory {
265-
t.Errorf("The number of objects in the current directory doesn't match.")
257+
s.T().Errorf("The number of objects in the current directory doesn't match.")
266258
return
267259
}
268260

269261
// destNonEmptyCopyDirectory/srcCopyDirectory - Dir
270262
if objs[0].Name() != EmptySrcDirectoryCopyTest || objs[0].IsDir() != true {
271-
t.Errorf("Error in copying directory.")
263+
s.T().Errorf("Error in copying directory.")
272264
return
273265
}
274266

275267
// destNonEmptyCopyDirectory/subDirInNonEmptyDestCopyDirectory - Dir
276268
if objs[1].Name() != SubDirInNonEmptyDestCopyDirectory || objs[1].IsDir() != true {
277-
t.Errorf("Existing object affected.")
269+
s.T().Errorf("Existing object affected.")
278270
return
279271
}
280272

281273
copyDirPath := path.Join(destDir, EmptySrcDirectoryCopyTest)
282-
checkIfCopiedEmptyDirectoryHasNoData(copyDirPath, t)
274+
s.checkIfCopiedEmptyDirectoryHasNoData(copyDirPath)
283275
}
284276

285277
// Copy SrcDirectory in DestDirectory
@@ -289,21 +281,19 @@ func TestCopyEmptyDirectoryInNonEmptyDirectory(t *testing.T) {
289281

290282
// Output
291283
// destEmptyCopyDirectory/emptySrcDirectoryCopyTest
292-
func TestCopyEmptyDirectoryInEmptyDirectory(t *testing.T) {
284+
func (s *operationsTestSuite) TestCopyEmptyDirectoryInEmptyDirectory() {
293285
testDir := setup.SetupTestDirectory(DirForOperationTests)
294286

295287
srcDir := path.Join(testDir, EmptySrcDirectoryCopyTest)
296-
operations.CreateDirectoryWithNFiles(0, srcDir, "", t)
288+
operations.CreateDirectoryWithNFiles(0, srcDir, "", s.T())
297289

298290
// Create below directory
299291
// destCopyDir -- Dir
300292
destDir := path.Join(testDir, DestEmptyCopyDirectory)
301-
operations.CreateDirectoryWithNFiles(0, destDir, "", t)
293+
operations.CreateDirectoryWithNFiles(0, destDir, "", s.T())
302294

303295
err := operations.CopyDir(srcDir, destDir)
304-
if err != nil {
305-
t.Errorf("Error in copying directory: %v", err)
306-
}
296+
require.NoError(s.T(), err, "Error in copying directory")
307297

308298
obj, err := os.ReadDir(destDir)
309299
if err != nil {
@@ -314,43 +304,41 @@ func TestCopyEmptyDirectoryInEmptyDirectory(t *testing.T) {
314304
// destEmptyCopyDirectory
315305
// destEmptyCopyDirectory/emptyDirectoryCopyTest
316306
if len(obj) != NumberOfObjectsInEmptyDestCopyDirectory {
317-
t.Errorf("The number of objects in the current directory doesn't match.")
307+
s.T().Errorf("The number of objects in the current directory doesn't match.")
318308
return
319309
}
320310

321311
// destEmptyCopyDirectory/srcCopyDirectory - Dir
322312
if obj[0].Name() != EmptySrcDirectoryCopyTest || obj[0].IsDir() != true {
323-
t.Errorf("Error in copying directory.")
313+
s.T().Errorf("Error in copying directory.")
324314
return
325315
}
326316

327317
copyDirPath := path.Join(destDir, EmptySrcDirectoryCopyTest)
328-
checkIfCopiedEmptyDirectoryHasNoData(copyDirPath, t)
318+
s.checkIfCopiedEmptyDirectoryHasNoData(copyDirPath)
329319
}
330320

331321
// Copy SrcDirectory in DestDirectory
332322
// emptySrcDirectoryCopyTest
333323

334324
// Output
335325
// destCopyDirectoryNotExist
336-
func TestCopyEmptyDirectoryInNonExistingDirectory(t *testing.T) {
326+
func (s *operationsTestSuite) TestCopyEmptyDirectoryInNonExistingDirectory() {
337327
testDir := setup.SetupTestDirectory(DirForOperationTests)
338328

339329
srcDir := path.Join(testDir, EmptySrcDirectoryCopyTest)
340-
operations.CreateDirectoryWithNFiles(0, srcDir, "", t)
330+
operations.CreateDirectoryWithNFiles(0, srcDir, "", s.T())
341331

342332
// destCopyDirectoryNotExist -- Dir
343333
destDir := path.Join(testDir, DestCopyDirectoryNotExist)
344334

345335
_, err := os.Stat(destDir)
346336
if err == nil {
347-
t.Errorf("destCopyDirectoryNotExist directory exist.")
337+
s.T().Errorf("destCopyDirectoryNotExist directory exist.")
348338
}
349339

350340
err = operations.CopyDir(srcDir, destDir)
351-
if err != nil {
352-
t.Errorf("Error in copying directory: %v", err)
353-
}
341+
require.NoError(s.T(), err, "Error in copying directory")
354342

355-
checkIfCopiedEmptyDirectoryHasNoData(destDir, t)
343+
s.checkIfCopiedEmptyDirectoryHasNoData(destDir)
356344
}

0 commit comments

Comments
 (0)