- Notifications
You must be signed in to change notification settings - Fork3
chore: rework RPC version to match new header spec#8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
36 changes: 0 additions & 36 deletionsTests/Vpn.Proto/ApiVersionTest.cs
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
14 changes: 7 additions & 7 deletionsTests/Vpn.Proto/RpcHeaderTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletionsTests/Vpn.Proto/RpcVersionTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
using Coder.Desktop.Vpn.Proto; | ||
using NUnit.Framework.Constraints; | ||
namespace Coder.Desktop.Tests.Vpn.Proto; | ||
[TestFixture] | ||
public class RpcVersionTest | ||
{ | ||
[Test(Description = "Parse a variety of version strings")] | ||
public void Parse() | ||
{ | ||
Assert.That(RpcVersion.Parse("2.1"), Is.EqualTo(new RpcVersion(2, 1))); | ||
Assert.That(RpcVersion.Parse("1.0"), Is.EqualTo(new RpcVersion(1, 0))); | ||
Assert.Throws<ArgumentException>(() => RpcVersion.Parse("cats")); | ||
Assert.Throws<ArgumentException>(() => RpcVersion.Parse("cats.dogs")); | ||
Assert.Throws<ArgumentException>(() => RpcVersion.Parse("1.dogs")); | ||
Assert.Throws<ArgumentException>(() => RpcVersion.Parse("1.0.1")); | ||
Assert.Throws<ArgumentException>(() => RpcVersion.Parse("11")); | ||
} | ||
private void IsCompatibleWithBothWays(RpcVersion a, RpcVersion b, IResolveConstraint c) | ||
{ | ||
Assert.That(a.IsCompatibleWith(b), c); | ||
Assert.That(b.IsCompatibleWith(a), c); | ||
} | ||
[Test(Description = "Test that versions are compatible")] | ||
public void IsCompatibleWith() | ||
{ | ||
var twoOne = new RpcVersion(2, 1); | ||
Assert.That(twoOne.IsCompatibleWith(twoOne), Is.EqualTo(twoOne)); | ||
// 2.1 && 2.2 => 2.1 | ||
IsCompatibleWithBothWays(twoOne, new RpcVersion(2, 2), Is.EqualTo(new RpcVersion(2, 1))); | ||
// 2.1 && 2.0 => 2.0 | ||
IsCompatibleWithBothWays(twoOne, new RpcVersion(2, 0), Is.EqualTo(new RpcVersion(2, 0))); | ||
// 2.1 && 3.1 => null | ||
IsCompatibleWithBothWays(twoOne, new RpcVersion(3, 1), Is.Null); | ||
// 2.1 && 1.1 => null | ||
IsCompatibleWithBothWays(twoOne, new RpcVersion(1, 1), Is.Null); | ||
} | ||
} | ||
[TestFixture] | ||
public class RpcVersionListTest | ||
{ | ||
[Test(Description = "Parse a variety of version list strings")] | ||
public void Parse() | ||
{ | ||
Assert.That(RpcVersionList.Parse("1.0"), Is.EqualTo(new RpcVersionList(new RpcVersion(1, 0)))); | ||
Assert.That(RpcVersionList.Parse("1.3,2.1"), | ||
Is.EqualTo(new RpcVersionList(new RpcVersion(1, 3), new RpcVersion(2, 1)))); | ||
var ex = Assert.Throws<ArgumentException>(() => RpcVersionList.Parse("0.1")); | ||
Assert.That(ex.InnerException, Is.Not.Null); | ||
Assert.That(ex.InnerException.Message, Does.Contain("Invalid major version")); | ||
ex = Assert.Throws<ArgumentException>(() => RpcVersionList.Parse("")); | ||
Assert.That(ex.InnerException, Is.Not.Null); | ||
Assert.That(ex.InnerException.Message, Does.Contain("Invalid version string")); | ||
ex = Assert.Throws<ArgumentException>(() => RpcVersionList.Parse("2.1,1.1")); | ||
Assert.That(ex.InnerException, Is.Not.Null); | ||
Assert.That(ex.InnerException.Message, Does.Contain("sorted")); | ||
ex = Assert.Throws<ArgumentException>(() => RpcVersionList.Parse("1.1,1.2")); | ||
Assert.That(ex.InnerException, Is.Not.Null); | ||
Assert.That(ex.InnerException.Message, Does.Contain("Duplicate major version")); | ||
} | ||
[Test(Description = "Validate a variety of version lists to test every error")] | ||
public void Validate() | ||
{ | ||
Assert.DoesNotThrow(() => | ||
new RpcVersionList(new RpcVersion(1, 3), new RpcVersion(2, 4), new RpcVersion(3, 0)).Validate()); | ||
var ex = Assert.Throws<ArgumentException>(() => new RpcVersionList(new RpcVersion(0, 1)).Validate()); | ||
Assert.That(ex.Message, Does.Contain("Invalid major version")); | ||
ex = Assert.Throws<ArgumentException>(() => | ||
new RpcVersionList(new RpcVersion(2, 1), new RpcVersion(1, 2)).Validate()); | ||
Assert.That(ex.Message, Does.Contain("sorted")); | ||
ex = Assert.Throws<ArgumentException>(() => | ||
new RpcVersionList(new RpcVersion(1, 1), new RpcVersion(1, 2)).Validate()); | ||
Assert.That(ex.Message, Does.Contain("Duplicate major version")); | ||
} | ||
private void IsCompatibleWithBothWays(RpcVersionList a, RpcVersionList b, IResolveConstraint c) | ||
{ | ||
Assert.That(a.IsCompatibleWith(b), c); | ||
Assert.That(b.IsCompatibleWith(a), c); | ||
} | ||
[Test(Description = "Check a variety of lists against each other to determine compatible version")] | ||
public void IsCompatibleWith() | ||
{ | ||
var list1 = RpcVersionList.Parse("1.2,2.4,3.2"); | ||
Assert.That(list1.IsCompatibleWith(list1), Is.EqualTo(new RpcVersion(3, 2))); | ||
IsCompatibleWithBothWays(list1, RpcVersionList.Parse("4.1,5.2"), Is.Null); | ||
IsCompatibleWithBothWays(list1, RpcVersionList.Parse("1.2,2.3"), Is.EqualTo(new RpcVersion(2, 3))); | ||
IsCompatibleWithBothWays(list1, RpcVersionList.Parse("2.3,3.3"), Is.EqualTo(new RpcVersion(3, 2))); | ||
} | ||
} |
40 changes: 40 additions & 0 deletionsTests/Vpn/SpeakerTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
103 changes: 0 additions & 103 deletionsVpn.Proto/ApiVersion.cs
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
14 changes: 7 additions & 7 deletionsVpn.Proto/RpcHeader.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.