Skip to content

Commit 3524619

Browse files
committed
test(setup): add special cases for configure
use last index for multiple existing path matches skip addition of trailing guard value for "credential.helper"
1 parent 8421cb7 commit 3524619

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

src/shared/Core.Tests/ApplicationTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,55 @@ public async Task Application_ConfigureAsync_EmptyAndGcmWithEmptyAfter_RemovesEx
178178
Assert.Equal(executablePath, actualValues[4]);
179179
}
180180

181+
[Fact]
182+
public async Task Application_ConfigureAsync_MultiGcmWithValidEmpty_DoesNothing()
183+
{
184+
const string emptyHelper = "";
185+
const string executablePath = "/usr/local/share/gcm-core/git-credential-manager";
186+
string key = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}";
187+
188+
var context = new TestCommandContext { AppPath = executablePath };
189+
IConfigurableComponent application = new Application(context);
190+
191+
context.Git.Configuration.Global[key] = new List<string>
192+
{
193+
executablePath, emptyHelper, executablePath
194+
};
195+
196+
await application.ConfigureAsync(ConfigurationTarget.User);
197+
198+
Assert.Single(context.Git.Configuration.Global);
199+
Assert.True(context.Git.Configuration.Global.TryGetValue(key, out var actualValues));
200+
Assert.Equal(3, actualValues.Count);
201+
Assert.Equal(executablePath, actualValues[0]);
202+
Assert.Equal(emptyHelper, actualValues[1]);
203+
Assert.Equal(executablePath, actualValues[2]);
204+
}
205+
206+
[Fact]
207+
public async Task Application_ConfigureAsync_EmptyOnly_AddsGcmOnly()
208+
{
209+
const string emptyHelper = "";
210+
const string executablePath = "/usr/local/share/gcm-core/git-credential-manager";
211+
string key = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}";
212+
213+
var context = new TestCommandContext { AppPath = executablePath };
214+
IConfigurableComponent application = new Application(context);
215+
216+
context.Git.Configuration.Global[key] = new List<string>
217+
{
218+
emptyHelper
219+
};
220+
221+
await application.ConfigureAsync(ConfigurationTarget.User);
222+
223+
Assert.Single(context.Git.Configuration.Global);
224+
Assert.True(context.Git.Configuration.Global.TryGetValue(key, out var actualValues));
225+
Assert.Equal(2, actualValues.Count);
226+
Assert.Equal(emptyHelper, actualValues[0]);
227+
Assert.Equal(executablePath, actualValues[1]);
228+
}
229+
181230
[Fact]
182231
public async Task Application_UnconfigureAsync_NoHelpers_DoesNothing()
183232
{

0 commit comments

Comments
 (0)