Skip to content

Commit

Permalink
Allure.Commons: configurable host name (#17)
Browse files Browse the repository at this point in the history
Allure.Commons: configurable title
Allure.SpecFlow: label.host is now read from title
  • Loading branch information
Bakanych committed Sep 19, 2018
1 parent eb5c2b6 commit 629474b
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 42 deletions.
9 changes: 9 additions & 0 deletions Allure.Commons.Tests/ConfigurationTests.cs
Expand Up @@ -49,6 +49,15 @@ public int ShouldConfigureIssueLinkPatternFromJson(string json)
return new AllureLifecycle(configFile).AllureConfiguration.Links.Count;
}

[Test]
public void ShouldConfigureTitle()
{
var json = @"{""allure"":{""title"": ""hello Allure""}}";
configFile = WriteConfig(json);
var actualTitle = new AllureLifecycle(configFile).AllureConfiguration.Title;
Assert.AreEqual("hello Allure", actualTitle);
}

[TearDown]
public void TearDown()
{
Expand Down
4 changes: 3 additions & 1 deletion Allure.Commons/Configuration/AllureConfiguration.cs
Expand Up @@ -6,14 +6,16 @@ namespace Allure.Commons.Configuration
{
public class AllureConfiguration
{
public string Title { get; }
public string Directory { get; } = "allure-results";
public HashSet<string> Links { get; } = new HashSet<string>();

private AllureConfiguration() { }

[JsonConstructor]
protected AllureConfiguration(string directory, HashSet<string> links)
protected AllureConfiguration(string title, string directory, HashSet<string> links)
{
Title = title ?? Title;
Directory = directory ?? Directory;
Links = links ?? Links;
}
Expand Down
140 changes: 112 additions & 28 deletions Allure.Commons/Model/allure2.Extensions.cs
Expand Up @@ -6,59 +6,143 @@ public enum SeverityLevel { normal, blocker, critical, minor, trivial }

public partial class TestResultContainer
{
public override string ToString() => name ?? uuid;
public override string ToString()
{
return name ?? uuid;
}
}

public partial class TestResult
{
public override string ToString() => name ?? uuid;
public override string ToString()
{
return name ?? uuid;
}
}

public partial class FixtureResult
{
public override string ToString() => name;
public override string ToString()
{
return name;
}
}

public partial class Label
{
public static Label TestType(string value) => new Label() { name = "testType", value = value };
public static Label TestType(string value)
{
return new Label() { name = "testType", value = value };
}

public static Label ParentSuite(string value)
{
return new Label() { name = "parentSuite", value = value };
}

public static Label Suite(string value)
{
return new Label() { name = "suite", value = value };
}

public static Label ParentSuite(string value) => new Label() { name = "parentSuite", value = value };
public static Label Suite(string value) => new Label() { name = "suite", value = value };
public static Label SubSuite(string value) => new Label() { name = "subSuite", value = value };
public static Label SubSuite(string value)
{
return new Label() { name = "subSuite", value = value };
}

public static Label Owner(string value)
{
return new Label() { name = "owner", value = value };
}

public static Label Owner(string value) => new Label() { name = "owner", value = value };
public static Label Severity(SeverityLevel value) => new Label() { name = "severity", value = value.ToString() };
public static Label Tag(string value) => new Label() { name = "tag", value = value };
public static Label Severity(SeverityLevel value)
{
return new Label() { name = "severity", value = value.ToString() };
}

public static Label Epic(string value) => new Label() { name = "epic", value = value };
public static Label Feature(string value) => new Label() { name = "feature", value = value };
public static Label Story(string value) => new Label() { name = "story", value = value };
public static Label Tag(string value)
{
return new Label() { name = "tag", value = value };
}

public static Label Package(string value) => new Label() { name = "package", value = value };
public static Label TestClass(string value) => new Label() { name = "testClass", value = value };
public static Label TestMethod(string value) => new Label() { name = "testMethod", value = value };
public static Label Epic(string value)
{
return new Label() { name = "epic", value = value };
}

public static Label Thread() => new Label()
public static Label Feature(string value)
{
name = "thread",
value = System.Threading.Thread.CurrentThread.Name ?? System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()
};
public static Label Host() => new Label()
return new Label() { name = "feature", value = value };
}

public static Label Story(string value)
{
name = "host",
value = Environment.MachineName ?? "Unknown host"
};
return new Label() { name = "story", value = value };
}

public static Label Package(string value)
{
return new Label() { name = "package", value = value };
}

public static Label TestClass(string value)
{
return new Label() { name = "testClass", value = value };
}

public static Label TestMethod(string value)
{
return new Label() { name = "testMethod", value = value };
}

public static Label Thread()
{
return new Label()
{
name = "thread",
value = System.Threading.Thread.CurrentThread.Name ?? System.Threading.Thread.CurrentThread.ManagedThreadId.ToString()
};
}

public static Label Host()
{
return new Label()
{
name = "host",
value = Environment.MachineName ?? "Unknown host"
};
}

public static Label Host(string value)
{
return new Label()
{
name = "host",
value = value
};
}
}

public partial class Link
{
public static Link Issue(string name, string url) => new Link() { name = name, type = "issue", url = url };
public static Link Issue(string name) => Issue(name, null);
public static Link Issue(string name, string url)
{
return new Link() { name = name, type = "issue", url = url };
}

public static Link Tms(string name, string url) => new Link() { name = name, type = "tms", url = url };
public static Link Tms(string name) => Tms(name, null);
public static Link Issue(string name)
{
return Issue(name, null);
}

public static Link Tms(string name, string url)
{
return new Link() { name = name, type = "tms", url = url };
}

public static Link Tms(string name)
{
return Tms(name, null);
}
}
}
27 changes: 15 additions & 12 deletions Allure.SpecFlowPlugin.Tests/IntegrationTests.cs
Expand Up @@ -11,14 +11,12 @@ namespace Allure.SpecFlowPlugin.Tests
[TestFixture]
public class IntegrationFixture
{
const string SCENARIO_PATTERN = "Scenario:";
const string FEATURE_PATTERN = "Feature:";

HashSet<string> scenarioTitles = new HashSet<string>();
HashSet<TestResultContainer> allureContainers = new HashSet<TestResultContainer>();
HashSet<TestResult> allureTestResults = new HashSet<TestResult>();

HashSet<TestResultContainer> specflowSuites = new HashSet<TestResultContainer>();
private const string SCENARIO_PATTERN = "Scenario:";
private const string FEATURE_PATTERN = "Feature:";
private readonly HashSet<string> scenarioTitles = new HashSet<string>();
private HashSet<TestResultContainer> allureContainers = new HashSet<TestResultContainer>();
private HashSet<TestResult> allureTestResults = new HashSet<TestResult>();
private readonly HashSet<TestResultContainer> specflowSuites = new HashSet<TestResultContainer>();


[OneTimeSetUp]
Expand Down Expand Up @@ -134,16 +132,21 @@ public void ShouldParseLinks()
});

}

[Test]
public void ShouldReadHostNameFromConfigTitle()
{
var hostNames = allureTestResults.SelectMany(x => x.labels.Where(l => l.name == "host").Select(l => l.value)).Distinct();
Assert.That(hostNames, Has.One.Items.And.All.EqualTo("5994A3F7-AF84-46AD-9393-000BB45553CC"));
}
private void ParseAllureSuites(string allureResultsDir)
{
var allureTestResultFiles = new DirectoryInfo(allureResultsDir).GetFiles("*-result.json");
var allureContainerFiles = new DirectoryInfo(allureResultsDir).GetFiles("*-container.json");
JsonSerializer serializer = new JsonSerializer();
var serializer = new JsonSerializer();

foreach (var fileInfo in allureContainerFiles)
{
using (StreamReader file = File.OpenText(fileInfo.FullName))
using (var file = File.OpenText(fileInfo.FullName))
{
var container = (TestResultContainer)serializer.Deserialize(file, typeof(TestResultContainer));
allureContainers.Add(container);
Expand All @@ -152,7 +155,7 @@ private void ParseAllureSuites(string allureResultsDir)

foreach (var fileInfo in allureTestResultFiles)
{
using (StreamReader file = File.OpenText(fileInfo.FullName))
using (var file = File.OpenText(fileInfo.FullName))
{
var testResult = (TestResult)serializer.Deserialize(file, typeof(TestResult));
allureTestResults.Add(testResult);
Expand Down
2 changes: 1 addition & 1 deletion Allure.SpecFlowPlugin/PluginHelper.cs
Expand Up @@ -64,7 +64,7 @@ internal static FixtureResult GetFixtureResult(HookBinding hook)
labels = new List<Label>
{
Label.Thread(),
Label.Host(),
string.IsNullOrWhiteSpace(AllureLifecycle.Instance.AllureConfiguration.Title) ? Label.Host() : Label.Host(AllureLifecycle.Instance.AllureConfiguration.Title),
Label.Feature(featureInfo.Title)
}
.Union(tags.Item1).ToList(),
Expand Down
1 change: 1 addition & 0 deletions Tests.SpecRun/allureConfig.json
@@ -1,5 +1,6 @@
{
"allure": {
"title": "5994A3F7-AF84-46AD-9393-000BB45553CC",
"directory": "allure-results",
"links": [
"https://example.org/{issue}",
Expand Down

0 comments on commit 629474b

Please sign in to comment.