Skip to content

Commit

Permalink
Merge #2410 Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
politas committed Apr 17, 2018
2 parents e05990e + 12bcdf0 commit 3af2ae2
Show file tree
Hide file tree
Showing 15 changed files with 433 additions and 69 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

All notable changes to this project will be documented in this file.

## v1.25.0
## v1.25.1

### Internal

- [Build] Add more tests (#2410 by: HebaruSan, DasSkelett; reviewed: politas)

## v1.25.0 (Wallops)

### Features

Expand Down Expand Up @@ -34,8 +40,8 @@ All notable changes to this project will be documented in this file.
- [Multiple] Clean-up and debuggability (#2399 by: HebaruSan; reviewed: politas)
- [Netkan] Don't double encode GitHub download URLs (#2402 by: HebaruSan; reviewed: politas)
- [Netkan] Option to override SpaceDock version with AVC version (#2406 by: HebaruSan; reviewed: politas)
- [GUI] Move AutoUpdate.CanUpdate check to resolve VisualStudio Designer Error (#2407 by: DasSkellet; reviewed: Olympic1, politas)
- [GUI] Better AutoUpdate.CanUpdate Error Message (#2408 by: DasSkellet; reviewed: politas)
- [GUI] Move AutoUpdate.CanUpdate check to resolve VisualStudio Designer Error (#2407 by: DasSkelett; reviewed: Olympic1, politas)
- [GUI] Better AutoUpdate.CanUpdate Error Message (#2408 by: DasSkelett; reviewed: politas)

### Internal

Expand Down
14 changes: 14 additions & 0 deletions Tests/Core/KSPPathUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ public void ToRelative()

}

[Test]
public void ToRelative_PathEqualsRoot_DontCrash()
{
// Arrange
string path = "/home/fionna/KSP";
string root = "/home/fionna/KSP";
// Act & Assert
Assert.DoesNotThrow(() =>
{
string s = CKAN.KSPPathUtils.ToRelative(path, root);
Assert.IsEmpty(s);
});
}

[Test]
public void ToAbsolute()
{
Expand Down
2 changes: 1 addition & 1 deletion Tests/Core/ModuleInstallerDirTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ModuleInstallerDirTest
private DisposableKSP _instance;
private CKAN.Registry _registry;
private CKAN.ModuleInstaller _installer;
private CKAN.CkanModule _testModule;
private CkanModule _testModule;
private string _gameDataDir;

/// <summary>
Expand Down
23 changes: 6 additions & 17 deletions Tests/Core/Relationships/RelationshipResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,8 @@ public void Constructor_ProvidesSatisfyDependencies()
mod_b,
depender
});

}


[Test]
public void Constructor_WithMissingDependants_Throws()
{
Expand All @@ -477,14 +475,13 @@ public void Constructor_WithMissingDependants_Throws()
options,
registry,
null));

}

[Test]
[Category("Version")]
[TestCase("1.0", "2.0")]
[TestCase("1.0", "0.2")]
[TestCase("0", "0.2")]
[TestCase("0", "0.2")]
[TestCase("1.0", "0")]
public void Constructor_WithMissingDependantsVersion_Throws(string ver, string dep)
{
Expand All @@ -502,7 +499,6 @@ public void Constructor_WithMissingDependantsVersion_Throws(string ver, string d
options,
registry,
null));

}

[Test]
Expand Down Expand Up @@ -530,7 +526,6 @@ public void Constructor_WithMissingDependantsVersionMin_Throws(string ver, strin
options,
registry,
null));

}

[Test]
Expand All @@ -553,7 +548,6 @@ public void Constructor_WithMissingDependantsVersionMax_Throws(string ver, strin
options,
registry,
null));

}

[Test]
Expand All @@ -566,10 +560,12 @@ public void Constructor_WithMissingDependantsVersionMinMax_Throws(string ver, st
var dependant = generator.GeneratorRandomModule(version: new ModuleVersion(ver));
var depender = generator.GeneratorRandomModule(depends: new List<RelationshipDescriptor>
{
new RelationshipDescriptor {
new RelationshipDescriptor
{
name = dependant.identifier,
min_version = new ModuleVersion(dep_min),
max_version = new ModuleVersion(dep_max)}
max_version = new ModuleVersion(dep_max)
}
});
list.Add(depender.identifier);
list.Add(dependant.identifier);
Expand All @@ -580,7 +576,6 @@ public void Constructor_WithMissingDependantsVersionMinMax_Throws(string ver, st
options,
registry,
null));

}

[Test]
Expand All @@ -607,7 +602,6 @@ public void Constructor_WithDependantVersion_ChooseCorrectly(string ver, string
dependant,
depender
});

}

[Test]
Expand All @@ -634,7 +628,6 @@ public void Constructor_WithDependantVersionMin_ChooseCorrectly(string ver, stri
dependant,
depender
});

}

[Test]
Expand All @@ -661,7 +654,6 @@ public void Constructor_WithDependantVersionMax_ChooseCorrectly(string ver, stri
dependant,
depender
});

}

[Test]
Expand All @@ -688,7 +680,6 @@ public void Constructor_WithDependantVersionMinMax_ChooseCorrectly(string ver, s
dependant,
depender
});

}

[Test]
Expand All @@ -708,7 +699,6 @@ public void Constructor_WithRegistryThatHasRequiredModuleRemoved_Throws()
null));
}


[Test]
public void ReasonFor_WithModsNotInList_ThrowsArgumentException()
{
Expand All @@ -722,7 +712,6 @@ public void ReasonFor_WithModsNotInList_ThrowsArgumentException()
var mod_not_in_resolver_list = generator.GeneratorRandomModule();
CollectionAssert.DoesNotContain(relationship_resolver.ModList(),mod_not_in_resolver_list);
Assert.Throws<ArgumentException>(() => relationship_resolver.ReasonFor(mod_not_in_resolver_list));

}

[Test]
Expand Down Expand Up @@ -802,7 +791,7 @@ public void AutodetectedCanSatisfyRelationships()
CkanModule mod = generator.GeneratorRandomModule(depends: depends);

new RelationshipResolver(
new CKAN.CkanModule[] { mod },
new CkanModule[] { mod },
RelationshipResolver.DefaultOpts(),
registry,
new KspVersionCriteria (KspVersion.Parse("1.0.0"))
Expand Down
112 changes: 108 additions & 4 deletions Tests/Core/Relationships/SanityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ public void FindUnsatisfiedDepends()
[Test]
public void ReverseDepends()
{
var mods = new List<CkanModule>
var mods = new List<CkanModule>()
{
registry.LatestAvailable("CustomBiomes",null),
registry.LatestAvailable("CustomBiomesKerbal",null),
registry.LatestAvailable("DogeCoinFlag",null)
registry.LatestAvailable("CustomBiomes", null),
registry.LatestAvailable("CustomBiomesKerbal", null),
registry.LatestAvailable("DogeCoinFlag", null)
};

// Make sure some of our expectations regarding dependencies are correct.
Expand Down Expand Up @@ -162,7 +162,110 @@ public void ReverseDepends()
expected.Clear();
to_remove.Clear();
TestDepends(to_remove, mods, null, null, expected, "Removing nothing");
}

[Test]
public void IsConsistent_MismatchedDependencyVersion_Inconsistent()
{
// Arrange
List<CkanModule> modules = new List<CkanModule>()
{
CkanModule.FromJson(@"{
""identifier"": ""depender"",
""version"": ""1.0.0"",
""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"",
""depends"": [ {
""name"": ""dependency"",
""version"": ""1.2.3""
} ]
}"),
CkanModule.FromJson(@"{
""identifier"": ""dependency"",
""version"": ""1.1.0"",
""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01""
}")
};

// Act & Assert
Assert.IsFalse(CKAN.SanityChecker.IsConsistent(modules));
}

[Test]
public void IsConsistent_MatchedDependencyVersion_Consistent()
{
// Arrange
List<CkanModule> modules = new List<CkanModule>()
{
CkanModule.FromJson(@"{
""identifier"": ""depender"",
""version"": ""1.0.0"",
""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"",
""depends"": [ {
""name"": ""dependency"",
""version"": ""1.2.3""
} ]
}"),
CkanModule.FromJson(@"{
""identifier"": ""dependency"",
""version"": ""1.2.3"",
""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01""
}")
};

// Act & Assert
Assert.IsTrue(CKAN.SanityChecker.IsConsistent(modules));
}

[Test]
public void IsConsistent_MismatchedConflictVersion_Consistent()
{
// Arrange
List<CkanModule> modules = new List<CkanModule>()
{
CkanModule.FromJson(@"{
""identifier"": ""depender"",
""version"": ""1.0.0"",
""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"",
""conflicts"": [ {
""name"": ""dependency"",
""version"": ""1.2.3""
} ]
}"),
CkanModule.FromJson(@"{
""identifier"": ""dependency"",
""version"": ""1.1.0"",
""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01""
}")
};

// Act & Assert
Assert.IsTrue(CKAN.SanityChecker.IsConsistent(modules));
}

[Test]
public void IsConsistent_MatchedConflictVersion_Inconsistent()
{
// Arrange
List<CkanModule> modules = new List<CkanModule>()
{
CkanModule.FromJson(@"{
""identifier"": ""depender"",
""version"": ""1.0.0"",
""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01"",
""conflicts"": [ {
""name"": ""dependency"",
""version"": ""1.2.3""
} ]
}"),
CkanModule.FromJson(@"{
""identifier"": ""dependency"",
""version"": ""1.2.3"",
""download"": ""https://kerbalstuff.com/mod/269/Dogecoin%20Flag/download/1.01""
}")
};

// Act & Assert
Assert.IsFalse(CKAN.SanityChecker.IsConsistent(modules));
}

private static void TestDepends(
Expand All @@ -189,5 +292,6 @@ private static void TestDepends(
// Check our actual results.
CollectionAssert.AreEquivalent(expected, results, message);
}

}
}
Loading

0 comments on commit 3af2ae2

Please sign in to comment.