Skip to content

Commit

Permalink
Tests to exercise new 'find' directive.
Browse files Browse the repository at this point in the history
More of these would be better... but hey, tests! :)

For KSP-CKAN#376.
  • Loading branch information
pjf committed Dec 24, 2014
1 parent 8055c62 commit 4644388
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
41 changes: 27 additions & 14 deletions CKAN/Tests/CKAN/ModuleInstaller.cs
Expand Up @@ -33,6 +33,17 @@ public void Setup()
mm_mod = Tests.TestData.ModuleManagerModule();
}

[Test]
public void Sanity()
{
// Test our assumptions are right with the data we're using.

// Our _find mod should have a find section, but not a file section.
CkanModule mod = Tests.TestData.DogeCoinFlag_101_module_find();
Assert.IsNull(mod.install[0].file);
Assert.IsNotNull(mod.install[0].find);
}

[Test]
public void GenerateDefaultInstall()
{
Expand Down Expand Up @@ -67,10 +78,17 @@ public void GenerateDefaultInstall()
}
}

[Test]
public void FindInstallableFiles()
// Test data: different ways to install the same file.
public static CkanModule[] doge_mods =
{
List<InstallableFile> contents = CKAN.ModuleInstaller.FindInstallableFiles(dogemod, dogezip, null);
Tests.TestData.DogeCoinFlag_101_module(),
Tests.TestData.DogeCoinFlag_101_module_find()
};

[Test][TestCaseSource("doge_mods")]
public void FindInstallableFiles(CkanModule mod)
{
List<InstallableFile> contents = CKAN.ModuleInstaller.FindInstallableFiles(mod, dogezip, null);
List<string> filenames = new List<string>();

Assert.IsNotNull(contents);
Expand All @@ -96,12 +114,12 @@ public void FindInstallableFiles()
Assert.Contains("DogeCoinFlag-1.01/GameData/DogeCoinFlag/Flags/dogecoin.png", filenames);
}

[Test]
public void FindInstallableFilesWithKSP()
[Test][TestCaseSource("doge_mods")]
public void FindInstallableFilesWithKSP(CkanModule mod)
{
using (var tidy = new Tests.DisposableKSP())
{
List<InstallableFile> contents = CKAN.ModuleInstaller.FindInstallableFiles(dogemod, dogezip, tidy.KSP);
List<InstallableFile> contents = CKAN.ModuleInstaller.FindInstallableFiles(mod, dogezip, tidy.KSP);

// See if we can find an expected estination path in the right place.
string file = contents
Expand All @@ -112,8 +130,6 @@ public void FindInstallableFilesWithKSP()
}
}

#pragma warning disable 0414

// GH #315, all of these should result in the same output.
// Even though they're not necessarily all spec-valid, we should accept them
// nonetheless.
Expand All @@ -127,8 +143,6 @@ public void FindInstallableFilesWithKSP()
"GameData/SuchTest\\"
};

#pragma warning restore 0414

[Test]
[TestCaseSource("SuchPaths")]
public void FindInstallbleFilesWithBonusPath(string path)
Expand Down Expand Up @@ -163,14 +177,13 @@ public void ModuleManagerInstall()
}
}

[Test]
[Test][TestCaseSource("doge_mods")]
// Make sure all our filters work.
public void FindInstallableFilesWithFilter()
public void FindInstallableFilesWithFilter(CkanModule mod)
{
string extra_doge = Tests.TestData.DogeCoinFlagZipWithExtras();
CkanModule dogemod = Tests.TestData.DogeCoinFlag_101_module();

List<InstallableFile> contents = CKAN.ModuleInstaller.FindInstallableFiles(dogemod, extra_doge, null);
List<InstallableFile> contents = CKAN.ModuleInstaller.FindInstallableFiles(mod, extra_doge, null);

var files = contents.Select(x => x.source.Name);

Expand Down
14 changes: 14 additions & 0 deletions CKAN/Tests/TestData.cs
Expand Up @@ -135,6 +135,20 @@ public static CkanModule DogeCoinFlag_101_module()
return CkanModule.FromJson(DogeCoinFlag_101());
}

/// <summary>
/// The Doge Coin flag we all love, but using `find` install stanzas.
/// </summary>
public static CkanModule DogeCoinFlag_101_module_find()
{
CkanModule doge = DogeCoinFlag_101_module();

// Hand hack in the 'find' directive.
doge.install[0].file = null;
doge.install[0].find = "DogeCoinFlag";

return doge;
}

// Identical to DogeCoinFlag_101, but with a spec version over 9000!
public static string FutureMetaData()
{
Expand Down

0 comments on commit 4644388

Please sign in to comment.