Where is the bug?
I thought that I was adding an innocent little feature, here:
public class CreateFolderIcon : IStartupTask { public void Execute(DocumentDatabase database) { var dataDirectory = Path.GetFullPath(database.Configuration.DataDirectory); var desktopIni = Path.Combine(dataDirectory, "desktop.ini"); var icon = Path.Combine(dataDirectory, "raven-data.ico"); if (File.Exists(desktopIni) && File.Exists(icon)) return; using (var iconFile = typeof(CreateFolderIcon).Assembly.GetManifestResourceStream("Raven.Database.Server.WebUI.raven-data.ico")) { File.WriteAllBytes(icon, iconFile.ReadData()); } File.WriteAllText(desktopIni, string.Format(@" [.ShellClassInfo] IconResource={0},0 [ViewState] Mode= Vid= FolderType=Generic ", icon)); File.SetAttributes(desktopIni, FileAttributes.Hidden | FileAttributes.System | FileAttributes.Archive); File.SetAttributes(dataDirectory, FileAttributes.ReadOnly); } }
But this resulted in every single test failing.
Can you figure out why?
Comments
The directory didn't exist when starting up the unit tests? Or maybe it's just because you set the folder to readonly and denied yourself to option to create files or somesuch (I don't really know what ReadOnly on folders does anyway)
direct File access in unit tests? how do you isolate that?
DataDirectory is unset / invalid because your tests and database run in memory?
Unit test bug, you aren't mocking file access so the files exist from the last run and/or the required folders do not exist?
Logical bug, you are testing that neither Desktop.ini or raven-data.ico exist and failing to take into account that only one of the two files might have been deleted.
@Peter,
Only if both exist then the method will be skipped, so if either is deleted it will create both again.
Still that doesn't explain why the tests would fail, can't set a directory to read-only in Explorer so can't test that.
my guess: File.SetAttributes() does not work on directories. You need to set DirectoryInfo.Attributes instead.
Not sure how you can write to your data directory with it set to readonly. That would sure stop your data files cold.
Configurator,
No, the directory is created by the tests
Ken!
This is a database that I am testing, remember?
Devio,
SetAttributes works, but it has an interesting side effect.
Setting a directory to readonly will not prevent from writing to files in it.
If you set dataDirectory to ReadOnly, then Raven will not be able to create or modify any files in the directory.
Should be:
Ok maybe I should have actually read the code properly before answering.
I'm thinking that the icon in the desktop.ini should not be the full path. Maybe just a relative path.
Or maybe IconResource should be IconFile?
Ok one more try.
Your tests teardown method tries to delete the data directory but can't because it's read only.
AndrewVos ,
YES
Is iconFile.ReadData() an extension method?
Roger,
Yes, standard stream handling
Do permissions have anything to do with it? Are the unittests run under a different user than RavenDb?
Peter,
No, same user.
Comment preview