8000 Test Push with a custom backend · philhack/libgit2sharp@97caa92 · GitHub
[go: up one dir, main page]

Skip to content

Commit 97caa92

Browse files
committed
Test Push with a custom backend
1 parent 41ef06e commit 97caa92

File tree

1 file changed

+52
-8
lines changed

1 file changed

+52
-8
lines changed

LibGit2Sharp.Tests/OdbBackendFixture.cs

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class OdbBackendFixture : BaseFixture
1212
{
1313
private const string content = "test\n";
1414

15-
private static void AddCommitToRepo(Repository repo)
15+
private static Commit AddCommitToRepo(Repository repo)
1616
{
1717
string relativeFilepath = "test.txt";
1818
Touch(repo.Info.WorkingDirectory, relativeFilepath, content);
@@ -23,7 +23,7 @@ private static void AddCommitToRepo(Repository repo)
2323
Assert.Equal("9daeafb9864cf43055ae93beb0afd6c7d144bfa4", ie.Id.Sha);
2424

2525
var author = new Signature("nulltoken", "emeric.fermas@gmail.com", DateTimeOffset.Parse("Wed, Dec 14 2011 08:29:03 +0100"));
26-
repo.Commit("Initial commit", author, author);
26+
var commit = repo.Commit("Initial commit", author, author);
2727

2828
relativeFilepath = "big.txt";
2929
var zeros = new string('0', 32*1024 + 3);
@@ -33,6 +33,8 @@ private static void AddCommitToRepo(Repository repo)
3333
ie = repo.Index[relativeFilepath];
3434
Assert.NotNull(ie);
3535
Assert.Equal("6518215c4274845a759cb498998fe696c42e3e0f", ie.Id.Sha);
36+
37+
return commit;
3638
}
3739

3840
private static void AssertGeneratedShas(Repository repo)
@@ -147,6 +149,34 @@ public void CanEnumerateTheContentOfTheObjectDatabase()
147149
}
148150
}
149151

152+
[Fact]
153+
public void CanPushWithACustomBackend()
154+
{
155+
string remoteRepoPath = InitNewRepository(true);
156+
string localRepoPath = InitNewRepository();
157+
Commit commit;
158+
159+
using (var localRepo = new Repository(localRepoPath))
160+
{
161+
localRepo.ObjectDatabase.AddBackend(new MockOdbBackend(), 5);
162+
163+
commit = AddCommitToRepo(localRepo);
164+
165+
Remote remote = localRepo.Network.Remotes.Add("origin", remoteRepoPath);
166+
167+
localRepo.Branches.Update(localRepo.Head,
168+
b => b.Remote = remote.Name,
169+
b => b.UpstreamBranch = localRepo.Head.CanonicalName);
170+
171+
localRepo.Network.Push(localRepo.Head);
172+
}
173+
174+
using (var remoteRepo = new Repository(remoteRepoPath))
175+
{
176+
Assert.Equal(commit, remoteRepo.Head.Tip);
177+
}
178+
}
179+
150180
#region MockOdbBackend
151181

152182
private class MockOdbBackend : OdbBackend
@@ -160,7 +190,8 @@ protected override OdbBackendOperations SupportedOperations
160190
OdbBackendOperations.Write |
161191
OdbBackendOperations.WriteStream |
162192
OdbBackendOperations.Exists |
163-
OdbBackendOperations.ForEach;
193+
OdbBackendOperations.ForEach |
194+
OdbBackendOperations.ReadHeader;
164195
}
165196
}
166197

@@ -270,16 +301,29 @@ public override bool Exists(ObjectId oid)
270301
return m_objectIdToContent.ContainsKey(oid);
271302
}
272303

304+
public override int ReadHeader(ObjectId oid, out int length, out ObjectType objectType)
305+
{
306+
objectType = default(ObjectType);
307+
length = 0;
308+
309+
MockGitObject gitObject;
310+
311+
if (!m_objectIdToContent.TryGetValue(oid, out gitObject))
312+
{
313+
return (int)ReturnCode.GIT_ENOTFOUND;
314+
}
315+
316+
objectType = gitObject.ObjectType;
317+
length = (int)gitObject.Length;
318+
319+
return (int)ReturnCode.GIT_OK;
320+
}
321+
273322
private readonly Dictionary<ObjectId, MockGitObject> m_objectIdToContent =
274323
new Dictionary<ObjectId, MockGitObject>();
275324

276325
#region Unimplemented
277326

278-
public override int ReadHeader(ObjectId oid, out int length, out ObjectType objectType)
279-
{
280-
throw new NotImplementedException();
281-
}
282-
283327
public override int ReadStream(ObjectId oid, out OdbBacken 4370 dStream stream)
284328
{
285329
throw new NotImplementedException();

0 commit comments

Comments
 (0)
0