public void LoadStatistics() { testDir.CreateDirectory().CreateTextFile(StatisticsPublisher.XmlFileName, "<statistics />"); XmlDocument statisticsDoc = new XmlDocument(); statisticsDoc.LoadXml(StatisticsPublisher.LoadStatistics(testDir.ToString())); XPathNavigator navigator = statisticsDoc.CreateNavigator(); XPathNodeIterator nodeIterator = navigator.Select("//timestamp/@day"); nodeIterator.MoveNext(); int day = Convert.ToInt32(nodeIterator.Current.Value); Assert.AreEqual(DateTime.Now.Day, day); nodeIterator = navigator.Select("//timestamp/@month"); nodeIterator.MoveNext(); string month = nodeIterator.Current.Value; Assert.AreEqual(DateTime.Now.ToString("MMM"), month); nodeIterator = navigator.Select("//timestamp/@year"); nodeIterator.MoveNext(); int year = Convert.ToInt32(nodeIterator.Current.Value); Assert.AreEqual(DateTime.Now.Year, year); }
public void ShouldAllowOverwritesEvenWhenDestinationHasReadOnlyAttributeSet() { SystemPath sourceFile = tempRoot.CreateEmptyFile("File1"); SystemPath targetFile = tempSubRoot.CreateEmptyFile("File2"); File.SetAttributes(targetFile.ToString(), FileAttributes.ReadOnly); new SystemIoFileSystem().Copy(sourceFile.ToString(), targetFile.ToString()); Assert.IsTrue(targetFile.Exists()); }
public void PublishDirShouldBeRelativeToIntegrationArtifactDirectory() { srcRoot.CreateSubDirectory("foo").CreateTextFile(fileName, fileContents); result.ArtifactDirectory = pubRoot.ToString(); publisher.PublishDir = "bar"; publisher.Run(result); labelPubDir = pubRoot.Combine("bar").Combine("99").Combine("foo"); Assert.IsTrue(labelPubDir.Combine(fileName).Exists(), "File not found in build number directory"); }
public void SourceRootShouldBeRelativeToIntegrationWorkingDirectory() { srcRoot.CreateSubDirectory("foo").CreateTextFile(fileName, fileContents); result.WorkingDirectory = srcRoot.ToString(); publisher.SourceDir = "foo"; publisher.Run(result); Assert.IsTrue(labelPubDir.Combine(fileName).Exists(), "File not found in build number directory"); }
public void ShouldSaveUnicodeToFile() { SystemPath tempFile = tempRoot.Combine("foo.txt"); Assert.IsFalse(tempFile.Exists()); new SystemIoFileSystem().Save(tempFile.ToString(), "hi there? håkan! \u307b"); Assert.IsTrue(tempFile.Exists()); using (StreamReader reader = File.OpenText(tempFile.ToString())) { Assert.AreEqual("hi there? håkan! \u307b", reader.ReadToEnd()); } }
public void ReadFromLockedLogFile() { SystemPath tempFile = tempDir.CreateEmptyFile("LockedFilename.log"); using (StreamWriter stream = File.CreateText(tempFile.ToString())) { stream.Write("foo"); stream.Write("bar"); stream.Flush(); ServerLogFileReader reader = new ServerLogFileReader(tempFile.ToString(), 10); Assert.AreEqual("foobar", reader.Read()); } }
public void ReadEmptyFile() { SystemPath filename = tempDir.CreateEmptyFile("ReadEmptyFile.log"); ServerLogFileReader reader = new ServerLogFileReader(filename.ToString(), 10); Assert.AreEqual("", reader.Read(), "Error reading empty log file"); }
public void ShouldCopyFileToDirectory() { SystemPath file1 = tempRoot.CreateEmptyFile("File1"); new SystemIoFileSystem().Copy(file1.ToString(), tempSubRoot.ToString()); Assert.IsTrue(tempSubRoot.Combine("File1").Exists()); }
public void ReadSingleLineFromLogFile() { string content = @"SampleLine"; SystemPath filename = tempDir.CreateTextFile("ReadSingleLineFromLogFile.log", content); ServerLogFileReader reader = new ServerLogFileReader(filename.ToString(), 10); Assert.AreEqual(content, reader.Read()); }
public void ShouldAllowOverwrites() { SystemPath sourceFile = tempRoot.CreateEmptyFile("File1"); SystemPath targetFile = tempSubRoot.CreateEmptyFile("File2"); new SystemIoFileSystem().Copy(sourceFile.ToString(), targetFile.ToString()); Assert.IsTrue(targetFile.Exists()); }
public void ShouldCopyDirectoryToDirectoryRecursively() { tempRoot.CreateEmptyFile("File1"); tempSubRoot.CreateEmptyFile("File2"); new SystemIoFileSystem().Copy(tempRoot.ToString(), tempOtherRoot.ToString()); Assert.IsTrue(tempOtherRoot.Combine("File1").Exists()); Assert.IsTrue(tempOtherRoot.Combine("subrepo").Combine("File2").Exists()); }
public void ReadTwice() { SystemPath filename = tempDir.CreateEmptyFile("Twice.Log"); ServerLogFileReader reader = new ServerLogFileReader(filename.ToString(), 10); String first = reader.Read(); String second = reader.Read(); Assert.AreEqual(first, second, "Error reading file twice with same reader"); }
public void ShouldSaveToFileAtomically() { SystemPath tempFile = tempRoot.Combine("foo.txt"); Assert.IsFalse(tempFile.Exists()); new SystemIoFileSystem().AtomicSave(tempFile.ToString(), "bar"); Assert.IsTrue(tempFile.Exists()); using (StreamReader reader = File.OpenText(tempFile.ToString())) { Assert.AreEqual("bar", reader.ReadToEnd()); } new SystemIoFileSystem().AtomicSave(tempFile.ToString(), "baz"); Assert.IsTrue(tempFile.Exists()); using (StreamReader reader = File.OpenText(tempFile.ToString())) { Assert.AreEqual("baz", reader.ReadToEnd()); } }
public void SetUp() { fileSystemMock = new Mock <IFileSystem>(); tempRoot = SystemPath.UniqueTempPath(); tempSubRoot = tempRoot.Combine("subrepo"); sc = new FileSourceControl((IFileSystem)fileSystemMock.Object); sc.RepositoryRoot = tempRoot.ToString(); }
public void SetUp() { fileSystemMock = new DynamicMock(typeof(IFileSystem)); tempRoot = SystemPath.UniqueTempPath(); tempSubRoot = tempRoot.Combine("subrepo"); sc = new FileSourceControl((IFileSystem)fileSystemMock.MockInstance); sc.RepositoryRoot = tempRoot.ToString(); }
public void SetUp() { srcRoot = SystemPath.UniqueTempPath(); pubRoot = SystemPath.UniqueTempPath(); publisher = new BuildPublisher(); publisher.PublishDir = pubRoot.ToString(); publisher.SourceDir = srcRoot.ToString(); result = IntegrationResultMother.CreateSuccessful("99"); labelPubDir = pubRoot.Combine("99"); }
protected void Init() { tempOutputFile = new TempDirectory().CreateTextFile("results.xml", "foo"); executorMock = new DynamicMock(typeof(ProcessExecutor)); task = new NUnitTask(executorMock.MockInstance as ProcessExecutor); task.Assemblies = TEST_ASSEMBLIES; task.NUnitPath = NUnitConsolePath; task.OutputFile = tempOutputFile.ToString(); result = Integration("testProject", WORKING_DIRECTORY, ARTIFACT_DIRECTORY); }
private static void VerifyWriteWithLock(SystemPath file) { using (Stream fileOutputStream = FileOperations.NewLockingOutputStream(file)) { try { // Checks that the file was locked. File.ReadAllText(file.ToString()); Assert.Fail("Lock attempt should have failed"); } catch (IOException) { // pass } byte[] bytes = Encoding.UTF8.GetBytes("fib"); fileOutputStream.Write(bytes, 0, bytes.Length); } Assert.AreEqual("fib", File.ReadAllText(file.ToString())); }
public void GetModifications_EmptyLocal() { tempRoot.CreateDirectory(); tempSubRoot.CreateDirectory(); string file1 = tempRoot.CreateTextFile("file1.txt", "foo").ToString(); string file2 = tempRoot.CreateTextFile("file2.txt", "bar").ToString(); string file3 = tempSubRoot.CreateTextFile("file3.txt", "bat").ToString(); Modification[] mods = sc.GetModifications(IntegrationResult(DateTime.MinValue), IntegrationResult(DateTime.MaxValue)); Assert.AreEqual(4, mods.Length); Assert.AreEqual("file1.txt", mods[0].FileName); Assert.AreEqual("file2.txt", mods[1].FileName); Assert.AreEqual(Path.GetFileName(tempSubRoot.ToString()), mods[2].FileName); Assert.AreEqual("file3.txt", mods[3].FileName); Assert.AreEqual(Path.GetDirectoryName(file1), mods[0].FolderName); Assert.AreEqual(Path.GetDirectoryName(file2), mods[1].FolderName); Assert.AreEqual(Path.GetFileName(tempSubRoot.ToString()), mods[2].FolderName); Assert.AreEqual(Path.GetDirectoryName(file3), mods[3].FolderName); Assert.AreEqual(new FileInfo(file1).LastWriteTime, mods[0].ModifiedTime); Assert.AreEqual(new FileInfo(file2).LastWriteTime, mods[1].ModifiedTime); Assert.AreEqual(new FileInfo(tempSubRoot.ToString()).LastWriteTime, mods[2].ModifiedTime); Assert.AreEqual(new FileInfo(file3).LastWriteTime, mods[3].ModifiedTime); mods = sc.GetModifications(IntegrationResult(DateTime.Now.AddHours(1)), IntegrationResult(DateTime.MaxValue)); Assert.AreEqual(0, mods.Length); }
public void GetModifications_EmptyLocal() { tempRoot.CreateDirectory(); tempSubRoot.CreateDirectory(); string file1 = tempRoot.CreateTextFile("file1.txt", "foo").ToString(); string file2 = tempRoot.CreateTextFile("file2.txt", "bar").ToString(); string file3 = tempSubRoot.CreateTextFile("file3.txt", "bat").ToString(); Modification[] mods = sc.GetModifications(IntegrationResult(DateTime.MinValue), IntegrationResult(DateTime.MaxValue)); using (new AssertionScope()) { mods.Length.Should().Be(4); mods[0].FileName.Should().Be("file1.txt"); mods[1].FileName.Should().Be("file2.txt"); mods[2].FileName.Should().Be(Path.GetFileName(tempSubRoot.ToString())); mods[3].FileName.Should().Be("file3.txt"); mods[0].FolderName.Should().Be(Path.GetDirectoryName(file1)); mods[1].FolderName.Should().Be(Path.GetDirectoryName(file2)); mods[2].FolderName.Should().Be(Path.GetFileName(tempSubRoot.ToString())); mods[3].FolderName.Should().Be(Path.GetDirectoryName(file3)); new FileInfo(file1).LastWriteTime.Should().BeCloseTo(mods[0].ModifiedTime, 100); new FileInfo(file2).LastWriteTime.Should().BeCloseTo(mods[1].ModifiedTime, 100); new FileInfo(tempSubRoot.ToString()).LastWriteTime.Should().BeCloseTo(mods[2].ModifiedTime, 100); new FileInfo(file3).LastWriteTime.Should().BeCloseTo(mods[3].ModifiedTime, 100); } mods = sc.GetModifications(IntegrationResult(DateTime.Now.AddHours(1)), IntegrationResult(DateTime.MaxValue)); mods.Length.Should().Be(0); }
/** * Checks if Docker is installed on the user's system and accessible by running the given {@code * docker} executable. * * @param dockerExecutable path to the executable to test running * @return {@code true} if Docker is installed on the user's system and accessible */ public static bool IsDockerInstalled(SystemPath dockerExecutable) { dockerExecutable = dockerExecutable ?? throw new ArgumentNullException(nameof(dockerExecutable)); try { new ProcessBuilder(dockerExecutable.ToString()).Start(); return(true); } catch (Win32Exception e) when(e.NativeErrorCode == Win32ErrorCodes.FileNotFound) { return(false); } }
public void ReadOutputFromSpecifiedProject() { string content = @"2006-11-24 20:09:52,000 [CCNet Server:INFO] Starting CruiseControl.NET Server 2006-11-24 20:09:53,000 [foo:INFO] Starting integrator for project: foo 2006-11-24 20:09:54,000 [bar:INFO] Starting integrator for project: bar 2006-11-24 20:09:55,000 [foo:INFO] No modifications detected 2006-11-24 20:09:56,000 [bar:INFO] No modifications detected."; SystemPath tempFile = tempDir.CreateTextFile("MultiProject.log", content); ServerLogFileReader reader = new ServerLogFileReader(tempFile.ToString(), 10); Assert.AreEqual(@"2006-11-24 20:09:53,000 [foo:INFO] Starting integrator for project: foo" + Environment.NewLine + "2006-11-24 20:09:55,000 [foo:INFO] No modifications detected", reader.Read("foo")); Assert.AreEqual(@"2006-11-24 20:09:54,000 [bar:INFO] Starting integrator for project: bar" + Environment.NewLine + "2006-11-24 20:09:56,000 [bar:INFO] No modifications detected.", reader.Read("bar")); }
public async Task TestBuildTarballAsync() { SystemPath outputPath = temporaryFolder.NewFolder().ToPath().Resolve("test.tar"); await BuildTarImageAsync( ImageReference.Of("gcr.io", "distroless/java", DISTROLESS_DIGEST), ImageReference.Of(null, "testtar", null), outputPath, new List <string>()).ConfigureAwait(false); progressChecker.CheckCompletion(); new Command("docker", "load", "--input", outputPath.ToString()).Run(); AssertLayerSizer(7, "testtar"); Assert.AreEqual( "Hello, world. An argument.\n", new Command("docker", "run", "--rm", "testtar").Run()); }
public void ReadExactInFile() { const int numLines = 10; string[] contentLines = GenerateContentLines(numLines); SystemPath filename = tempDir.CreateTextFile("ReadExactInFile.log", LinesToString(contentLines)); ServerLogFileReader reader = new ServerLogFileReader(filename.ToString(), numLines); String[] readLines = StringToLines(reader.Read()); // All of file should be read Assert.AreEqual(numLines, readLines.Length); for (int i = 0; i < readLines.Length; i++) { Assert.AreEqual(contentLines[i], readLines[i]); } }
public void ReadLessThanInFile() { const int numFileLines = 15; string[] contentLines = GenerateContentLines(numFileLines); SystemPath filename = tempDir.CreateTextFile("ReadLessThanInFile.log", LinesToString(contentLines)); const int numReadLines = 10; ServerLogFileReader reader = new ServerLogFileReader(filename.ToString(), numReadLines); String[] readLines = StringToLines(reader.Read()); Assert.AreEqual(numReadLines, readLines.Length); for (int i = 0; i < readLines.Length; i++) { Assert.AreEqual(contentLines[numFileLines - numReadLines + i], readLines[i]); } }
public void GetModifications_EmptyLocal() { tempRoot.CreateDirectory(); tempSubRoot.CreateDirectory(); string file1 = tempRoot.CreateTextFile("file1.txt", "foo").ToString(); string file2 = tempRoot.CreateTextFile("file2.txt", "bar").ToString(); string file3 = tempSubRoot.CreateTextFile("file3.txt", "bat").ToString(); Modification[] mods = sc.GetModifications(IntegrationResult(DateTime.MinValue), IntegrationResult(DateTime.MaxValue)); Array.Sort( mods, (left, right) => { int result = left.FolderName.CompareTo(right.FolderName); if (result == 0) { result = left.FileName.CompareTo(right.FileName); } return(result); } ); using (new AssertionScope()) { mods.Length.Should().Be(4); mods[0].FileName.Should().Be("file1.txt", "FileName[0]"); mods[1].FileName.Should().Be("file2.txt", "FileName[1]"); mods[2].FileName.Should().Be("file3.txt", "FileName[2]"); mods[3].FileName.Should().Be(Path.GetFileName(tempSubRoot.ToString()), "FileName[3]"); mods[0].FolderName.Should().Be(Path.GetDirectoryName(file1), "FolderName[0]"); mods[1].FolderName.Should().Be(Path.GetDirectoryName(file2), "FolderName[1]"); mods[2].FolderName.Should().Be(Path.GetDirectoryName(file3), "FolderName[2]"); mods[3].FolderName.Should().Be(Path.GetFileName(tempSubRoot.ToString()), "FolderName[3]"); new FileInfo(file1).LastWriteTime.Should().BeCloseTo(mods[0].ModifiedTime, 100, "LastWriteTime[0]"); new FileInfo(file2).LastWriteTime.Should().BeCloseTo(mods[1].ModifiedTime, 100, "LastWriteTime[1]"); new FileInfo(file3).LastWriteTime.Should().BeCloseTo(mods[2].ModifiedTime, 100, "LastWriteTime[2]"); new FileInfo(tempSubRoot.ToString()).LastWriteTime.Should().BeCloseTo(mods[3].ModifiedTime, 100, "LastWriteTime[3]"); } mods = sc.GetModifications(IntegrationResult(DateTime.Now.AddHours(1)), IntegrationResult(DateTime.MaxValue)); mods.Length.Should().Be(0); }
public void MissingDirectoryThrowsException() { Assert.IsFalse(tempRoot.Exists(), "Temporary directory should not exist: " + tempRoot.ToString()); Assert.That(delegate { sc.GetModifications(IntegrationResult(DateTime.MinValue), IntegrationResult(DateTime.MaxValue)); }, Throws.TypeOf <DirectoryNotFoundException>()); }
internal static Instant GetLastModifiedTime(SystemPath systemPath) { return(Instant.FromDateTimeUtc(File.GetLastWriteTimeUtc(systemPath.ToString()))); }
/** * Instantiates with a {@code docker} executable and environment variables. * * @param dockerExecutable path to {@code docker} * @param dockerEnvironment environment variables for {@code docker} */ private DockerClient(SystemPath dockerExecutable, ImmutableDictionary <string, string> dockerEnvironment) : this(DefaultProcessBuilderFactory(dockerExecutable.ToString(), dockerEnvironment)) { }
public void LoadReadsFileContentCorrectly() { SystemPath tempFile = tempRoot.CreateTextFile("foo.txt", "bar"); Assert.AreEqual("bar", new SystemIoFileSystem().Load(tempFile.ToString()).ReadToEnd()); }