/// <exception cref="System.Exception"/> public virtual void TestDFInvalidPath() { // Generate a path that doesn't exist Random random = new Random(unchecked ((long)(0xDEADBEEFl))); FilePath file = null; byte[] bytes = new byte[64]; while (file == null) { random.NextBytes(bytes); string invalid = new string("/" + bytes); FilePath invalidFile = new FilePath(invalid); if (!invalidFile.Exists()) { file = invalidFile; } } DF df = new DF(file, 0l); try { df.GetMount(); } catch (FileNotFoundException e) { // expected, since path does not exist GenericTestUtils.AssertExceptionContains(file.GetName(), e); } }
/// <exception cref="System.Exception"/> public virtual void TestDFMalformedOutput() { DF df = new DF(new FilePath("/"), 0l); BufferedReader reader = new BufferedReader(new StringReader("Filesystem 1K-blocks Used Available Use% Mounted on\n" + "/dev/sda5 19222656 10597036 7649060 59% /")); df.ParseExecResult(reader); df.ParseOutput(); reader = new BufferedReader(new StringReader("Filesystem 1K-blocks Used Available Use% Mounted on" )); df.ParseExecResult(reader); try { df.ParseOutput(); NUnit.Framework.Assert.Fail("Expected exception with missing line!"); } catch (IOException e) { GenericTestUtils.AssertExceptionContains("Fewer lines of output than expected", e ); System.Console.Out.WriteLine(e.ToString()); } reader = new BufferedReader(new StringReader("Filesystem 1K-blocks Used Available Use% Mounted on\n" + " ")); df.ParseExecResult(reader); try { df.ParseOutput(); NUnit.Framework.Assert.Fail("Expected exception with empty line!"); } catch (IOException e) { GenericTestUtils.AssertExceptionContains("Unexpected empty line", e); System.Console.Out.WriteLine(e.ToString()); } reader = new BufferedReader(new StringReader("Filesystem 1K-blocks Used Available Use% Mounted on\n" + " 19222656 10597036 7649060 59% /")); df.ParseExecResult(reader); try { df.ParseOutput(); NUnit.Framework.Assert.Fail("Expected exception with missing field!"); } catch (IOException e) { GenericTestUtils.AssertExceptionContains("Could not parse line: ", e); System.Console.Out.WriteLine(e.ToString()); } }
/// <exception cref="System.Exception"/> public virtual void TestGetMountCurrentDirectory() { FilePath currentDirectory = new FilePath("."); string workingDir = currentDirectory.GetAbsoluteFile().GetCanonicalPath(); DF df = new DF(new FilePath(workingDir), 0L); string mountPath = df.GetMount(); FilePath mountDir = new FilePath(mountPath); Assert.True("Mount dir [" + mountDir.GetAbsolutePath() + "] should exist." , mountDir.Exists()); Assert.True("Mount dir [" + mountDir.GetAbsolutePath() + "] should be directory." , mountDir.IsDirectory()); Assert.True("Working dir [" + workingDir + "] should start with [" + mountPath + "].", workingDir.StartsWith(mountPath)); }