Skip to content

Commit 4ea2dcf

Browse files
committed
Moved GitPreparerTests into Core test project
1 parent af0408b commit 4ea2dcf

File tree

4 files changed

+37
-90
lines changed

4 files changed

+37
-90
lines changed

src/GitVersionExe.Tests/GitPreparerTests.cs renamed to src/GitVersionCore.Tests/GitPreparerTests.cs

Lines changed: 9 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,10 @@ public void WorksCorrectlyWithRemoteRepository(string branchName, string expecte
3939

4040
fixture.Repository.CreateBranch(SpecificBranchName);
4141

42-
var arguments = new Arguments
43-
{
44-
TargetPath = tempDir,
45-
TargetUrl = fixture.RepositoryPath
46-
};
47-
4842
// Copy contents into working directory
4943
File.Copy(Path.Combine(fixture.RepositoryPath, "TestFile.txt"), Path.Combine(tempDir, "TestFile.txt"));
5044

51-
if (!string.IsNullOrWhiteSpace(branchName))
52-
{
53-
arguments.TargetBranch = branchName;
54-
}
55-
56-
var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
45+
var gitPreparer = new GitPreparer(fixture.RepositoryPath, null, new Authentication(), branchName, false, tempDir);
5746
gitPreparer.Initialise(false, null);
5847
dynamicRepositoryPath = gitPreparer.GetDotGitDirectory();
5948

@@ -91,14 +80,7 @@ public void UpdatesExistingDynamicRepository()
9180
{
9281
mainRepositoryFixture.Repository.MakeCommits(1);
9382

94-
var arguments = new Arguments
95-
{
96-
TargetPath = tempDir,
97-
TargetUrl = mainRepositoryFixture.RepositoryPath,
98-
TargetBranch = "master"
99-
};
100-
101-
var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
83+
var gitPreparer = new GitPreparer(mainRepositoryFixture.RepositoryPath, null, new Authentication(), "master", false, tempDir);
10284
gitPreparer.Initialise(false, null);
10385
dynamicRepositoryPath = gitPreparer.GetDotGitDirectory();
10486

@@ -139,13 +121,7 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
139121
expectedDynamicRepoLocation = Path.Combine(tempPath, fixture.RepositoryPath.Split('\\').Last());
140122
Directory.CreateDirectory(expectedDynamicRepoLocation);
141123

142-
var arguments = new Arguments
143-
{
144-
TargetPath = tempDir,
145-
TargetUrl = fixture.RepositoryPath
146-
};
147-
148-
var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
124+
var gitPreparer = new GitPreparer(fixture.RepositoryPath, null, new Authentication(), null, false, tempDir);
149125
gitPreparer.Initialise(false, null);
150126

151127
gitPreparer.IsDynamicGitRepository.ShouldBe(true);
@@ -166,46 +142,13 @@ public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken()
166142
public void WorksCorrectlyWithLocalRepository()
167143
{
168144
var tempDir = Path.GetTempPath();
169-
170-
var arguments = new Arguments
171-
{
172-
TargetPath = tempDir
173-
};
174-
175-
var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
145+
var gitPreparer = new GitPreparer(null, null, null, null, false, tempDir);
176146
var dynamicRepositoryPath = gitPreparer.GetDotGitDirectory();
177147

178148
dynamicRepositoryPath.ShouldBe(null);
179149
gitPreparer.IsDynamicGitRepository.ShouldBe(false);
180150
}
181151

182-
[Test]
183-
public void UsesGitVersionConfigWhenCreatingDynamicRepository()
184-
{
185-
var localRepoPath = PathHelper.GetTempPath();
186-
var repoBasePath = Path.GetDirectoryName(PathHelper.GetTempPath());
187-
Directory.CreateDirectory(localRepoPath);
188-
189-
try
190-
{
191-
using (var remote = new EmptyRepositoryFixture(new Config()))
192-
{
193-
remote.Repository.MakeACommit();
194-
var configFile = Path.Combine(localRepoPath, "GitVersionConfig.yaml");
195-
File.WriteAllText(configFile, "next-version: 1.0.0");
196-
197-
var arguments = string.Format(" /url {0} /dynamicRepoLocation {1}", remote.RepositoryPath, repoBasePath);
198-
var results = GitVersionHelper.ExecuteIn(localRepoPath, arguments, false);
199-
results.OutputVariables.SemVer.ShouldBe("1.0.0");
200-
}
201-
}
202-
finally
203-
{
204-
DeleteHelper.DeleteGitRepository(localRepoPath);
205-
DeleteHelper.DeleteGitRepository(repoBasePath);
206-
}
207-
}
208-
209152
[Test]
210153
public void UsingDynamicRepositoryWithFeatureBranchWorks()
211154
{
@@ -218,17 +161,9 @@ public void UsingDynamicRepositoryWithFeatureBranchWorks()
218161
{
219162
using (var mainRepositoryFixture = new EmptyRepositoryFixture(new Config()))
220163
{
221-
var commitId = mainRepositoryFixture.Repository.MakeACommit().Id.Sha;
222-
223-
var arguments = new Arguments
224-
{
225-
TargetPath = tempDir,
226-
TargetUrl = mainRepositoryFixture.RepositoryPath,
227-
TargetBranch = "feature1",
228-
CommitId = commitId
229-
};
164+
mainRepositoryFixture.Repository.MakeACommit();
230165

231-
var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
166+
var gitPreparer = new GitPreparer(mainRepositoryFixture.RepositoryPath, null, new Authentication(), "feature1", false, tempDir);
232167
gitPreparer.Initialise(true, null);
233168

234169
mainRepositoryFixture.Repository.CreateBranch("feature1").Checkout();
@@ -254,16 +189,9 @@ public void UsingDynamicRepositoryWithoutTargetBranchFails()
254189
{
255190
using (var mainRepositoryFixture = new EmptyRepositoryFixture(new Config()))
256191
{
257-
var commitId = mainRepositoryFixture.Repository.MakeACommit().Id.Sha;
258-
259-
var arguments = new Arguments
260-
{
261-
TargetPath = tempDir,
262-
TargetUrl = mainRepositoryFixture.RepositoryPath,
263-
CommitId = commitId
264-
};
192+
mainRepositoryFixture.Repository.MakeACommit();
265193

266-
var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
194+
var gitPreparer = new GitPreparer(mainRepositoryFixture.RepositoryPath, null, new Authentication(), null, false, tempDir);
267195
gitPreparer.Initialise(true, null);
268196

269197
Assert.Throws<Exception>(() => gitPreparer.Initialise(true, null));
@@ -285,13 +213,7 @@ public void TestErrorThrownForInvalidRepository()
285213

286214
try
287215
{
288-
var arguments = new Arguments
289-
{
290-
TargetPath = tempDir,
291-
TargetUrl = "http://127.0.0.1/testrepo.git"
292-
};
293-
294-
var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
216+
var gitPreparer = new GitPreparer("http://127.0.0.1/testrepo.git", null, new Authentication(), null, false, tempDir);
295217

296218
Assert.Throws<Exception>(() => gitPreparer.Initialise(true, null));
297219
}
@@ -300,6 +222,4 @@ public void TestErrorThrownForInvalidRepository()
300222
Directory.Delete(tempDir, true);
301223
}
302224
}
303-
304-
// TODO test around normalisation
305225
}

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<Compile Include="Fixtures\RemoteRepositoryFixture.cs" />
125125
<Compile Include="GitDirFinderTests.cs" />
126126
<Compile Include="Fixtures\BaseGitFlowRepositoryFixture.cs" />
127+
<Compile Include="GitPreparerTests.cs" />
127128
<Compile Include="GitVersionContextTests.cs" />
128129
<Compile Include="Helpers\DirectoryHelper.cs" />
129130
<Compile Include="Init\InitScenarios.cs" />

src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,31 @@ public void InvalidArgumentsExitCodeShouldNotBeZero()
5555
result.Output.ShouldContain("Failed to parse arguments");
5656
}
5757
}
58+
59+
[Test]
60+
public void UsesGitVersionConfigWhenCreatingDynamicRepository()
61+
{
62+
var localRepoPath = PathHelper.GetTempPath();
63+
var repoBasePath = Path.GetDirectoryName(PathHelper.GetTempPath());
64+
Directory.CreateDirectory(localRepoPath);
65+
66+
try
67+
{
68+
using (var remote = new EmptyRepositoryFixture(new Config()))
69+
{
70+
remote.Repository.MakeACommit();
71+
var configFile = Path.Combine(localRepoPath, "GitVersionConfig.yaml");
72+
File.WriteAllText(configFile, "next-version: 1.0.0");
73+
74+
var arguments = string.Format(" /url {0} /dynamicRepoLocation {1}", remote.RepositoryPath, repoBasePath);
75+
var results = GitVersionHelper.ExecuteIn(localRepoPath, arguments, false);
76+
results.OutputVariables.SemVer.ShouldBe("1.0.0");
77+
}
78+
}
79+
finally
80+
{
81+
DeleteHelper.DeleteGitRepository(localRepoPath);
82+
DeleteHelper.DeleteGitRepository(repoBasePath);
83+
}
84+
}
5885
}

src/GitVersionExe.Tests/GitVersionExe.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
<Compile Include="ArgumentParserTests.cs" />
111111
<Compile Include="ExecCmdLineArgumentTest.cs" />
112112
<Compile Include="ExecutionResults.cs" />
113-
<Compile Include="GitPreparerTests.cs" />
114113
<Compile Include="GitVersionHelper.cs" />
115114
<Compile Include="HelpWriterTests.cs" />
116115
<Compile Include="MsBuildProjectArgTest.cs" />

0 commit comments

Comments
 (0)