Skip to content

Allow overriding of the config file path #1691

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 25 additions & 99 deletions src/GitVersionCore.Tests/ConfigProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
[TestFixture]
public class ConfigProviderTests : TestBase
{
private const string DefaultRepoPath = "c:\\MyGitRepo";
private const string DefaultWorkingPath = "c:\\MyGitRepo\\Working";
private const string DefaultRepoPath = @"c:\MyGitRepo";

string repoPath;
string workingPath;
IFileSystem fileSystem;
ConfigFileLocator configFileLocator;

[SetUp]
public void Setup()
{
fileSystem = new TestFileSystem();
configFileLocator = new DefaultConfigFileLocator();
repoPath = DefaultRepoPath;
workingPath = DefaultWorkingPath;

ShouldlyConfiguration.ShouldMatchApprovedDefaults.LocateTestMethodUsingAttribute<TestAttribute>();
}
Expand All @@ -49,7 +48,7 @@ public void CanReadOldDocument()
tag: rc
";
SetupConfigFileContent(text);
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator));
error.Message.ShouldContainWithoutWhitespace(@"GitVersion configuration file contains old configuration, please fix the following errors:
GitVersion branch configs no longer are keyed by regexes, update:
dev(elop)?(ment)?$ -> develop
Expand All @@ -62,15 +61,15 @@ assemblyVersioningScheme has been replaced by assembly-versioning-scheme
[Test]
public void OverwritesDefaultsWithProvidedConfig()
{
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
const string text = @"
next-version: 2.0.0
branches:
develop:
mode: ContinuousDeployment
tag: dev";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.NextVersion.ShouldBe("2.0.0");
config.Branches["develop"].Increment.ShouldBe(defaultConfig.Branches["develop"].Increment);
Expand All @@ -81,10 +80,9 @@ public void OverwritesDefaultsWithProvidedConfig()
[Test]
public void AllBranchesModeWhenUsingMainline()
{
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
const string text = @"mode: Mainline";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
var branches = config.Branches.Select(x => x.Value);
branches.All(branch => branch.VersioningMode == VersioningMode.Mainline).ShouldBe(true);
}
Expand All @@ -98,7 +96,7 @@ public void CanRemoveTag()
release:
tag: """"";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.NextVersion.ShouldBe("2.0.0");
config.Branches["release"].Tag.ShouldBe(string.Empty);
Expand All @@ -113,7 +111,7 @@ public void RegexIsRequired()
bug:
tag: bugfix";
SetupConfigFileContent(text);
var ex = Should.Throw<GitVersionConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
var ex = Should.Throw<GitVersionConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator));
ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'regex'\n\n" +
"See http://gitversion.readthedocs.io/en/latest/configuration/ for more info");
}
Expand All @@ -128,7 +126,7 @@ public void SourceBranchIsRequired()
regex: 'bug[/-]'
tag: bugfix";
SetupConfigFileContent(text);
var ex = Should.Throw<GitVersionConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
var ex = Should.Throw<GitVersionConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator));
ex.Message.ShouldBe("Branch configuration 'bug' is missing required configuration 'source-branches'\n\n" +
"See http://gitversion.readthedocs.io/en/latest/configuration/ for more info");
}
Expand All @@ -144,7 +142,7 @@ public void CanProvideConfigForNewBranch()
tag: bugfix
source-branches: []";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.Branches["bug"].Regex.ShouldBe("bug[/-]");
config.Branches["bug"].Tag.ShouldBe("bugfix");
Expand All @@ -155,7 +153,7 @@ public void NextVersionCanBeInteger()
{
const string text = "next-version: 2";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.NextVersion.ShouldBe("2.0");
}
Expand All @@ -165,7 +163,7 @@ public void NextVersionCanHaveEnormousMinorVersion()
{
const string text = "next-version: 2.118998723";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.NextVersion.ShouldBe("2.118998723");
}
Expand All @@ -175,7 +173,7 @@ public void NextVersionCanHavePatch()
{
const string text = "next-version: 2.12.654651698";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.NextVersion.ShouldBe("2.12.654651698");
}
Expand All @@ -186,7 +184,7 @@ public void NextVersionCanHavePatch()
[MethodImpl(MethodImplOptions.NoInlining)]
public void CanWriteOutEffectiveConfiguration()
{
var config = ConfigurationProvider.GetEffectiveConfigAsString(repoPath, fileSystem);
var config = ConfigurationProvider.GetEffectiveConfigAsString(repoPath, fileSystem, configFileLocator);

config.ShouldMatchApproved();
}
Expand All @@ -201,7 +199,7 @@ public void CanUpdateAssemblyInformationalVersioningScheme()

SetupConfigFileContent(text);

var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
config.AssemblyInformationalFormat.ShouldBe("{NugetVersion}");
Expand All @@ -217,7 +215,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithMultipleVariables(

SetupConfigFileContent(text);

var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
config.AssemblyInformationalFormat.ShouldBe("{Major}.{Minor}.{Patch}");
Expand All @@ -236,7 +234,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithFullSemVer()

SetupConfigFileContent(text);

var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
config.AssemblyInformationalFormat.ShouldBe("{FullSemVer}");
Expand All @@ -247,7 +245,7 @@ public void CanReadDefaultDocument()
{
const string text = "";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
config.AssemblyFileVersioningScheme.ShouldBe(AssemblyFileVersioningScheme.MajorMinorPatch);
config.AssemblyInformationalFormat.ShouldBe(null);
Expand All @@ -269,55 +267,6 @@ public void VerifyAliases()
propertiesMissingAlias.ShouldBeEmpty();
}

[TestCase(DefaultRepoPath)]
[TestCase(DefaultWorkingPath)]
public void WarnOnExistingGitVersionConfigYamlFile(string path)
{
SetupConfigFileContent(string.Empty, ConfigurationProvider.ObsoleteConfigFileName, path);

var logOutput = string.Empty;
Action<string> action = info => { logOutput = info; };
using (Logger.AddLoggersTemporarily(action, action, action, action))
{
ConfigurationProvider.Verify(workingPath, repoPath, fileSystem);
}
var configFileDeprecatedWarning = string.Format("{0}' is deprecated, use '{1}' instead", ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.DefaultConfigFileName);
logOutput.Contains(configFileDeprecatedWarning).ShouldBe(true);
}

[TestCase(DefaultRepoPath)]
[TestCase(DefaultWorkingPath)]
public void WarnOnAmbiguousConfigFilesAtTheSameProjectRootDirectory(string path)
{
SetupConfigFileContent(string.Empty, ConfigurationProvider.ObsoleteConfigFileName, path);
SetupConfigFileContent(string.Empty, ConfigurationProvider.DefaultConfigFileName, path);

var logOutput = string.Empty;
Action<string> action = info => { logOutput = info; };
using (Logger.AddLoggersTemporarily(action, action, action, action))
{
ConfigurationProvider.Verify(workingPath, repoPath, fileSystem);
}

var configFileDeprecatedWarning = string.Format("Ambiguous config files at '{0}'", path);
logOutput.Contains(configFileDeprecatedWarning).ShouldBe(true);
}

[TestCase(ConfigurationProvider.DefaultConfigFileName, ConfigurationProvider.DefaultConfigFileName)]
[TestCase(ConfigurationProvider.DefaultConfigFileName, ConfigurationProvider.ObsoleteConfigFileName)]
[TestCase(ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.DefaultConfigFileName)]
[TestCase(ConfigurationProvider.ObsoleteConfigFileName, ConfigurationProvider.ObsoleteConfigFileName)]
public void ThrowsExceptionOnAmbiguousConfigFileLocation(string repoConfigFile, string workingConfigFile)
{
var repositoryConfigFilePath = SetupConfigFileContent(string.Empty, repoConfigFile, repoPath);
var workingDirectoryConfigFilePath = SetupConfigFileContent(string.Empty, workingConfigFile, workingPath);

WarningException exception = Should.Throw<WarningException>(() => { ConfigurationProvider.Verify(workingPath, repoPath, fileSystem); });

var expecedMessage = string.Format("Ambiguous config file selection from '{0}' and '{1}'", workingDirectoryConfigFilePath, repositoryConfigFilePath);
exception.Message.ShouldBe(expecedMessage);
}

[Test]
public void NoWarnOnGitVersionYmlFile()
{
Expand All @@ -327,12 +276,12 @@ public void NoWarnOnGitVersionYmlFile()
Action<string> action = info => { s = info; };
using (Logger.AddLoggersTemporarily(action, action, action, action))
{
ConfigurationProvider.Provide(repoPath, fileSystem);
ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);
}
s.Length.ShouldBe(0);
}

string SetupConfigFileContent(string text, string fileName = ConfigurationProvider.DefaultConfigFileName)
string SetupConfigFileContent(string text, string fileName = DefaultConfigFileLocator.DefaultFileName)
{
return SetupConfigFileContent(text, fileName, repoPath);
}
Expand All @@ -345,29 +294,9 @@ string SetupConfigFileContent(string text, string fileName, string path)
return fullPath;
}

[Test]
public void WarnOnObsoleteIsDevelopBranchConfigurationSetting()
{
const string text = @"
assembly-versioning-scheme: MajorMinorPatch
branches:
master:
tag: beta
is-develop: true";

OldConfigurationException exception = Should.Throw<OldConfigurationException>(() =>
{
LegacyConfigNotifier.Notify(new StringReader(text));
});

const string expectedMessage = @"'is-develop' is deprecated, use 'tracks-release-branches' instead.";
exception.Message.ShouldContain(expectedMessage);
}

[Test]
public void ShouldUseSpecifiedSourceBranchesForDevelop()
{
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
const string text = @"
next-version: 2.0.0
branches:
Expand All @@ -376,31 +305,29 @@ public void ShouldUseSpecifiedSourceBranchesForDevelop()
source-branches: ['develop']
tag: dev";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.Branches["develop"].SourceBranches.ShouldBe(new List<string> { "develop" });
}

[Test]
public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForDevelop()
{
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
const string text = @"
next-version: 2.0.0
branches:
develop:
mode: ContinuousDeployment
tag: dev";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.Branches["develop"].SourceBranches.ShouldBe(new List<string>());
}

[Test]
public void ShouldUseSpecifiedSourceBranchesForFeature()
{
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
const string text = @"
next-version: 2.0.0
branches:
Expand All @@ -409,23 +336,22 @@ public void ShouldUseSpecifiedSourceBranchesForFeature()
source-branches: ['develop', 'release']
tag: dev";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.Branches["feature"].SourceBranches.ShouldBe(new List<string> { "develop", "release" });
}

[Test]
public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForFeature()
{
var defaultConfig = ConfigurationProvider.Provide(repoPath, fileSystem);
const string text = @"
next-version: 2.0.0
branches:
feature:
mode: ContinuousDeployment
tag: dev";
SetupConfigFileContent(text);
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
var config = ConfigurationProvider.Provide(repoPath, fileSystem, configFileLocator);

config.Branches["feature"].SourceBranches.ShouldBe(
new List<string> { "develop", "master", "release", "feature", "support", "hotfix" });
Expand Down
Loading