Skip to content

Commit 76d9dbd

Browse files
committed
Add more unit tests and logging
1 parent fc60627 commit 76d9dbd

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

internal/file/file_manager_service.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ func (fms *FileManagerService) DetermineFileActions(
386386
// If file currently exists on disk, is being tracked in manifest and file hash is different.
387387
// Treat it as a file update.
388388
if ok && modifiedFile.File.GetFileMeta().GetHash() != currentFile.GetFileMeta().GetHash() {
389+
slog.DebugContext(ctx, "Tracked file requires updating", "file_name", fileName)
389390
modifiedFile.Action = model.Update
390391
fileDiff[fileName] = modifiedFile
391392

@@ -395,6 +396,7 @@ func (fms *FileManagerService) DetermineFileActions(
395396
// If file doesn't exist on disk.
396397
// Treat it as adding a new file.
397398
if fileStats, statErr := os.Stat(fileName); errors.Is(statErr, os.ErrNotExist) {
399+
slog.DebugContext(ctx, "New untracked file to created", "file_name", fileName)
398400
modifiedFile.Action = model.Add
399401
fileDiff[fileName] = modifiedFile
400402

@@ -415,6 +417,7 @@ func (fms *FileManagerService) DetermineFileActions(
415417
}
416418

417419
if metadataOfFileOnDisk.GetHash() != modifiedFile.File.GetFileMeta().GetHash() {
420+
slog.DebugContext(ctx, "Untracked file requires updating", "file_name", fileName)
418421
modifiedFile.Action = model.Update
419422
fileDiff[fileName] = modifiedFile
420423
}

internal/file/file_manager_service_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,24 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
805805
expectedContent: make(map[string][]byte),
806806
expectedError: nil,
807807
},
808+
{
809+
name: "Test 4: File is actually a directory",
810+
allowedDirs: []string{tempDir},
811+
modifiedFiles: map[string]*model.FileCache{
812+
tempDir: {
813+
File: &mpi.File{
814+
FileMeta: protos.FileMeta(tempDir, files.GenerateHash(fileContent)),
815+
},
816+
},
817+
},
818+
currentFiles: make(map[string]*mpi.File),
819+
expectedCache: map[string]*model.FileCache(nil),
820+
expectedContent: make(map[string][]byte),
821+
expectedError: fmt.Errorf(
822+
"unable to create file %s since a directory with the same name already exists on the data plane",
823+
tempDir,
824+
),
825+
},
808826
}
809827

810828
for _, test := range tests {
@@ -828,7 +846,13 @@ func TestFileManagerService_DetermineFileActions(t *testing.T) {
828846
test.currentFiles,
829847
test.modifiedFiles,
830848
)
831-
require.NoError(tt, fileActionErr)
849+
850+
if test.expectedError != nil {
851+
require.EqualError(tt, fileActionErr, test.expectedError.Error())
852+
} else {
853+
require.NoError(tt, fileActionErr)
854+
}
855+
832856
assert.Equal(tt, test.expectedCache, diff)
833857
})
834858
}

0 commit comments

Comments
 (0)