Skip to content

Commit ebf1fa6

Browse files
committed
Added test to ensure that mkdocs.yml is up to date.
1 parent fa370dd commit ebf1fa6

File tree

1 file changed

+46
-11
lines changed

1 file changed

+46
-11
lines changed

src/GitVersionCore.Tests/DocumentationTests.cs

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
[TestFixture]
1515
public class DocumentationTests
1616
{
17+
private DirectoryInfo docsDirectory;
18+
19+
[OneTimeSetUp]
20+
public void OneTimeSetUp()
21+
{
22+
docsDirectory = GetDocsDirectory();
23+
}
24+
1725
[Test]
1826
public void ConfigurationDocumentationIsUpToDate()
1927
{
@@ -54,8 +62,44 @@ public void VariableDocumentationIsUpToDate()
5462
}
5563
}
5664

65+
[Test]
66+
public void DocumentationIndexIsUpToDate()
67+
{
68+
var documentationIndexFile = ReadDocumentationFile("../mkdocs.yml");
69+
var docsDirectoryPath = new Uri(docsDirectory.FullName, UriKind.Absolute);
70+
71+
Console.WriteLine(docsDirectoryPath);
72+
73+
foreach (var markdownFile in docsDirectory.EnumerateFiles("*.md", SearchOption.AllDirectories))
74+
{
75+
var fullPath = new Uri(markdownFile.FullName, UriKind.Absolute);
76+
var relativePath = docsDirectoryPath
77+
.MakeRelativeUri(fullPath)
78+
.ToString()
79+
.Replace("docs/", string.Empty);
80+
81+
Console.WriteLine(fullPath);
82+
Console.WriteLine(relativePath);
83+
84+
documentationIndexFile.ShouldContain(relativePath, () => string.Format("The file '{0}' is not listed in 'mkdocs.yml'.", relativePath));
85+
}
86+
}
87+
88+
private string ReadDocumentationFile(string relativeDocumentationFilePath)
89+
{
90+
var documentationFilePath = Path.Combine(docsDirectory.FullName, relativeDocumentationFilePath);
91+
// Normalize path separators and such.
92+
documentationFilePath = new FileInfo(documentationFilePath).FullName;
93+
94+
if (!File.Exists(documentationFilePath))
95+
{
96+
throw new FileNotFoundException(string.Format("The documentation file '{0}' couldn't be found.", documentationFilePath), documentationFilePath);
97+
}
5798

58-
static string ReadDocumentationFile(string relativeDocumentationFilePath)
99+
return File.ReadAllText(documentationFilePath);
100+
}
101+
102+
private static DirectoryInfo GetDocsDirectory()
59103
{
60104
var currentDirectory = new FileInfo(typeof(DocumentationTests).Assembly.Location).Directory;
61105
while (currentDirectory != null)
@@ -78,15 +122,6 @@ static string ReadDocumentationFile(string relativeDocumentationFilePath)
78122
throw new DirectoryNotFoundException("Couldn't find the 'docs' directory.");
79123
}
80124

81-
var documentationFilePath = Path.Combine(currentDirectory.FullName, relativeDocumentationFilePath);
82-
// Normalize path separators and such.
83-
documentationFilePath = new FileInfo(documentationFilePath).FullName;
84-
85-
if (!File.Exists(documentationFilePath))
86-
{
87-
throw new FileNotFoundException(string.Format("The documentation file '{0}' couldn't be found.", documentationFilePath), documentationFilePath);
88-
}
89-
90-
return File.ReadAllText(documentationFilePath);
125+
return currentDirectory;
91126
}
92127
}

0 commit comments

Comments
 (0)