Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
replace Logger with ILog
Add TestLogAppender
  • Loading branch information
arturcic committed Oct 18, 2019
commit 40ad2952889d8ba84ce0b6313ddb01404cf3d29a
17 changes: 12 additions & 5 deletions src/GitVersionCore.Tests/LoggerTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NUnit.Framework;
using Shouldly;
using GitVersion.Helpers;
using GitVersion.Log;

namespace GitVersionCore.Tests
{
Expand All @@ -18,8 +18,10 @@ public void LoggerObscuresPassword(string protocol)

void Action(string info) => s = info;

using (Logger.AddLoggersTemporarily(Action, Action, Action, Action))
Logger.Info($"{protocol}://{username}:{password}@workspace.visualstudio.com/DefaultCollection/_git/CAS");
var logAppender = new TestLogAppender(Action);
var log = new Log(logAppender);

log.Info($"{protocol}://{username}:{password}@workspace.visualstudio.com/DefaultCollection/_git/CAS");

s.Contains(password).ShouldBe(false);
}
Expand All @@ -28,10 +30,15 @@ public void LoggerObscuresPassword(string protocol)
public void UsernameWithoutPassword()
{
var s = string.Empty;

void Action(string info) => s = info;

var logAppender = new TestLogAppender(Action);
var log = new Log(logAppender);

const string repoUrl = "http://[email protected]/DefaultCollection/_git/CAS";
using (Logger.AddLoggersTemporarily(Action, Action, Action, Action))
Logger.Info(repoUrl);

log.Info(repoUrl);

s.Contains(repoUrl).ShouldBe(true);
}
Expand Down
19 changes: 19 additions & 0 deletions src/GitVersionCore.Tests/TestLogAppender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using GitVersion.Log;

namespace GitVersionCore.Tests
{
public class TestLogAppender : ILogAppender
{
private readonly Action<string> logAction;

public TestLogAppender(Action<string> logAction)
{
this.logAction = logAction;
}
public void WriteTo(LogLevel level, string message)
{
logAction(message);
}
}
}
5 changes: 3 additions & 2 deletions src/GitVersionCore/Log/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ namespace GitVersion.Log
public sealed class Log : ILog
{
private readonly IEnumerable<ILogAppender> appenders;
private static readonly Regex ObscurePasswordRegex = new Regex("(https?://)(.+)(:.+@)", RegexOptions.Compiled);
private readonly Regex ObscurePasswordRegex = new Regex("(https?://)(.+)(:.+@)", RegexOptions.Compiled);
private readonly StringBuilder sb;
private string indent = string.Empty;
private StringBuilder sb;

public Log(params ILogAppender[] appenders)
{
this.appenders = appenders ?? Array.Empty<ILogAppender>();
sb = new StringBuilder();
Verbosity = Verbosity.Normal;
}

public Verbosity Verbosity { get; set; }
Expand Down