Skip to content

Commit

Permalink
CKAN.dll: LatestAvailable now requires a version number
Browse files Browse the repository at this point in the history
This means we can never go looking up mods which may be the wrong
version for our install by accident. It may also fix some edge cases
like #602 where we may show the wrong versions being available.

Most of the changes in this commit are to the test cases, which now
require the mandatory argument. :)

Tested that this closes #610 with our NEAR test example.
  • Loading branch information
pjf committed Dec 17, 2014
1 parent 5b79ed4 commit e3ce310
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions CKAN/CKAN/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public List<CkanModule> Incompatible(KSPVersion ksp_version)

if (available == null)
{
incompatible.Add(LatestAvailable(candidate));
incompatible.Add(LatestAvailable(candidate, null));
}
}

Expand All @@ -422,7 +422,7 @@ public List<CkanModule> Incompatible(KSPVersion ksp_version)

// TODO: Consider making this internal, because practically everything should
// be calling LatestAvailableWithProvides()
public CkanModule LatestAvailable(string module, KSPVersion ksp_version = null)
public CkanModule LatestAvailable(string module, KSPVersion ksp_version)
{
log.DebugFormat("Finding latest available for {0}", module);

Expand Down
2 changes: 1 addition & 1 deletion CKAN/GUI/GUIMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public GUIMod(CkanModule mod, Registry registry, KSPVersion current_ksp_version)
Authors = mod.author == null ? "N/A" : String.Join(",", mod.author);

var installedVersion = registry.InstalledVersion(mod.identifier);
var latestVersion = registry.LatestAvailable(mod.identifier);
var latestVersion = registry.LatestAvailable(mod.identifier, current_ksp_version);
var kspVersion = mod.ksp_version;

InstalledVersion = installedVersion != null ? installedVersion.ToString() : "-";
Expand Down
2 changes: 1 addition & 1 deletion CKAN/GUI/MainInstall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ private void UpdateRecommendedDialog(Dictionary<string, List<string>> mods, bool

try
{
module = RegistryManager.Instance(manager.CurrentInstance).registry.LatestAvailable(pair.Key);
module = RegistryManager.Instance(manager.CurrentInstance).registry.LatestAvailable(pair.Key, CurrentInstance.Version());
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion CKAN/GUI/MainModList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public List<KeyValuePair<CkanModule, GUIModChangeType>> ComputeChangeSetFromModL
foreach (var reverseDependencies in modulesToRemove.Select(mod => installer.FindReverseDependencies(mod)))
{
//TODO This would be a good place to have a event that alters the row's graphics to show it will be removed
var modules = reverseDependencies.Select(rDep => registry.LatestAvailable(rDep));
var modules = reverseDependencies.Select(rDep => registry.LatestAvailable(rDep, current_instance.Version()));
changeset.UnionWith(
modules.Select(mod => new KeyValuePair<CkanModule, GUIModChangeType>(mod, GUIModChangeType.Remove)));
}
Expand Down
12 changes: 6 additions & 6 deletions CKAN/Tests/CKAN/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public void TxEmbeddedCommit()
{
reg = CKAN.Registry.Empty();
reg.AddAvailable(module);
Assert.AreEqual(identifier, reg.LatestAvailable(identifier).identifier);
Assert.AreEqual(identifier, reg.LatestAvailable(identifier, null).identifier);
scope.Complete();
}
Assert.AreEqual(identifier, reg.LatestAvailable(identifier).identifier);
Assert.AreEqual(identifier, reg.LatestAvailable(identifier, null).identifier);
}

[Test]
Expand All @@ -114,11 +114,11 @@ public void TxCommit()
using (var scope = new TransactionScope())
{
registry.AddAvailable(module);
Assert.AreEqual(module.identifier, registry.LatestAvailable(identifier).identifier);
Assert.AreEqual(module.identifier, registry.LatestAvailable(identifier, null).identifier);

scope.Complete();
}
Assert.AreEqual(module.identifier, registry.LatestAvailable(identifier).identifier);
Assert.AreEqual(module.identifier, registry.LatestAvailable(identifier, null).identifier);
}

[Test]
Expand All @@ -129,14 +129,14 @@ public void TxRollback()
using (var scope = new TransactionScope())
{
registry.AddAvailable(module);
Assert.AreEqual(module.identifier, registry.LatestAvailable(identifier).identifier);
Assert.AreEqual(module.identifier, registry.LatestAvailable(identifier,null).identifier);

scope.Dispose(); // Rollback, our module should no longer be available.
}

Assert.Throws<ModuleNotFoundKraken>(delegate
{
registry.LatestAvailable(identifier);
registry.LatestAvailable(identifier,null);
});
}

Expand Down
36 changes: 18 additions & 18 deletions CKAN/Tests/CKAN/Relationships/SanityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void Void()
public void DogeCoin()
{
// Test with a module that depends and conflicts with nothing.
var mods = new List<CkanModule> {registry.LatestAvailable("DogeCoinFlag")};
var mods = new List<CkanModule> {registry.LatestAvailable("DogeCoinFlag",null)};

Assert.IsTrue(CKAN.SanityChecker.IsConsistent(mods), "DogeCoinFlag");
}
Expand All @@ -49,13 +49,13 @@ public void CustomBiomes()
{
var mods = new List<CkanModule>();

mods.Add(registry.LatestAvailable("CustomBiomes"));
mods.Add(registry.LatestAvailable("CustomBiomes",null));
Assert.IsFalse(CKAN.SanityChecker.IsConsistent(mods), "CustomBiomes without data");

mods.Add(registry.LatestAvailable("CustomBiomesKerbal"));
mods.Add(registry.LatestAvailable("CustomBiomesKerbal",null));
Assert.IsTrue(CKAN.SanityChecker.IsConsistent(mods), "CustomBiomes with stock data");

mods.Add(registry.LatestAvailable("CustomBiomesRSS"));
mods.Add(registry.LatestAvailable("CustomBiomesRSS",null));
Assert.IsFalse(CKAN.SanityChecker.IsConsistent(mods), "CustomBiomes with conflicting data");
}

Expand All @@ -70,17 +70,17 @@ public void CustomBiomesWithDlls()

// This would actually be a terrible thing for users to have, but it tests the
// relationship we want.
mods.Add(registry.LatestAvailable("CustomBiomesKerbal"));
mods.Add(registry.LatestAvailable("CustomBiomesKerbal",null));
Assert.IsTrue(CKAN.SanityChecker.IsConsistent(mods, dlls), "CustomBiomes DLL, with config added");

mods.Add(registry.LatestAvailable("CustomBiomesRSS"));
mods.Add(registry.LatestAvailable("CustomBiomesRSS",null));
Assert.IsFalse(CKAN.SanityChecker.IsConsistent(mods, dlls), "CustomBiomes with conflicting data");
}

[Test]
public void ConflictWithDll()
{
var mods = new List<CKAN.Module> { registry.LatestAvailable("SRL") };
var mods = new List<CKAN.Module> { registry.LatestAvailable("SRL",null) };
var dlls = new List<string> { "QuickRevert" };

Assert.IsTrue(CKAN.SanityChecker.IsConsistent(mods), "SRL can be installed by itself");
Expand All @@ -92,9 +92,9 @@ public void ModulesToProvides()
{
var mods = new List<CKAN.Module>
{
registry.LatestAvailable("CustomBiomes"),
registry.LatestAvailable("CustomBiomesKerbal"),
registry.LatestAvailable("DogeCoinFlag")
registry.LatestAvailable("CustomBiomes",null),
registry.LatestAvailable("CustomBiomesKerbal",null),
registry.LatestAvailable("DogeCoinFlag",null)
};

var provides = CKAN.SanityChecker.ModulesToProvides(mods);
Expand All @@ -112,13 +112,13 @@ public void FindUnmetDependencies()
var dlls = new List<string>();
Assert.IsEmpty(CKAN.SanityChecker.FindUnmetDependencies(mods, dlls), "Empty list");

mods.Add(registry.LatestAvailable("DogeCoinFlag"));
mods.Add(registry.LatestAvailable("DogeCoinFlag",null));
Assert.IsEmpty(CKAN.SanityChecker.FindUnmetDependencies(mods, dlls), "DogeCoinFlag");

mods.Add(registry.LatestAvailable("CustomBiomes"));
mods.Add(registry.LatestAvailable("CustomBiomes",null));
Assert.Contains("CustomBiomesData", CKAN.SanityChecker.FindUnmetDependencies(mods, dlls).Keys, "Missing CustomBiomesData");

mods.Add(registry.LatestAvailable("CustomBiomesKerbal"));
mods.Add(registry.LatestAvailable("CustomBiomesKerbal",null));
Assert.IsEmpty(CKAN.SanityChecker.FindUnmetDependencies(mods, dlls), "CBD+CBK");

mods.RemoveAll(x => x.identifier == "CustomBiomes");
Expand All @@ -132,14 +132,14 @@ public void ReverseDepends()
{
var mods = new List<CKAN.Module>
{
registry.LatestAvailable("CustomBiomes"),
registry.LatestAvailable("CustomBiomesKerbal"),
registry.LatestAvailable("DogeCoinFlag")
registry.LatestAvailable("CustomBiomes",null),
registry.LatestAvailable("CustomBiomesKerbal",null),
registry.LatestAvailable("DogeCoinFlag",null)
};

// Make sure some of our expectations regarding dependencies are correct.
Assert.Contains("CustomBiomes", registry.LatestAvailable("CustomBiomesKerbal").depends.Select(x => x.name).ToList());
Assert.Contains("CustomBiomesData", registry.LatestAvailable("CustomBiomes").depends.Select(x => x.name).ToList());
Assert.Contains("CustomBiomes", registry.LatestAvailable("CustomBiomesKerbal",null).depends.Select(x => x.name).ToList());
Assert.Contains("CustomBiomesData", registry.LatestAvailable("CustomBiomes",null).depends.Select(x => x.name).ToList());

// Removing DCF should only remove itself.
var to_remove = new List<string>();
Expand Down

0 comments on commit e3ce310

Please sign in to comment.