Skip to content
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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ trim_trailing_whitespace=true
insert_final_newline=true

[*]
charset = utf-8
indent_style = tab
indent_size = 4

Expand Down
15 changes: 15 additions & 0 deletions .github/add-license-headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
script_path=$(dirname $(realpath -s $0))/../

function add_license () {
(find "$script_path" -name $1 | grep -v "/bin/" | grep -v "/obj/" )|while read fname; do
line=$(sed -n '2p;3q' "$fname")
if ! [[ "$line" == " * Licensed to Elasticsearch B.V. under one or more contributor" ]] ; then
# awk joins the header with the existing file, inserting a newline between them
awk '(NR>1 && FNR==1){print ""}1' "${script_path}.github/license-header.txt" "$fname" > "${fname}.new"
mv "${fname}.new" "$fname"
fi
done
}

add_license "*.cs"
45 changes: 45 additions & 0 deletions .github/check-license-headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

# Check that source code files in this repo have the appropriate license
# header.

if [ "$TRACE" != "" ]; then
export PS4='${BASH_SOURCE}:${LINENO}: ${FUNCNAME[0]:+${FUNCNAME[0]}(): }'
set -o xtrace
fi
set -o errexit
set -o pipefail

TOP=$(cd "$(dirname "$0")/.." >/dev/null && pwd)
NLINES=$(wc -l .github/license-header.txt | awk '{print $1}')

function check_license_header {
local f
f=$1
if ! diff -a --strip-trailing-cr .github/license-header.txt <(head -$NLINES "$f") >/dev/null; then
echo "check-license-headers: error: '$f' does not have required license header, see 'diff -u .github/license-header.txt <(head -$NLINES $f)'"
return 1
else
return 0
fi
}

cd "$TOP"
nErrors=0
for f in $(git ls-files | grep '\.cs$'); do
if ! check_license_header $f; then
nErrors=$((nErrors+1))
fi
done

for f in $(git ls-files | grep '\.fs$'); do
if ! check_license_header $f; then
nErrors=$((nErrors+1))
fi
done

if [[ $nErrors -eq 0 ]]; then
exit 0
else
exit 1
fi
3 changes: 3 additions & 0 deletions .github/license-header.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
15 changes: 15 additions & 0 deletions .github/workflows/license.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: License headers

on: [pull_request]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Check license headers
run: |
./.github/check-license-headers.sh
4 changes: 4 additions & 0 deletions build/scripts/CommandLine.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

module CommandLine

open Argu
Expand Down
4 changes: 4 additions & 0 deletions build/scripts/Paths.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

module Paths

open System
Expand Down
6 changes: 5 additions & 1 deletion build/scripts/Program.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module Program
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

module Program

open Argu
open Bullseye
Expand Down
4 changes: 4 additions & 0 deletions build/scripts/Targets.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

module Targets

open Argu
Expand Down
10 changes: 5 additions & 5 deletions examples/Elastic.Managed.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

Expand All @@ -14,13 +14,13 @@ public static class Program
public static void Main(string[] args)
{
var version = "6.3.0";
var esHome = Environment.ExpandEnvironmentVariables($@"%LOCALAPPDATA%\ElasticManaged\{version}\elasticsearch-{version}");
var esHome =
Environment.ExpandEnvironmentVariables(
$@"%LOCALAPPDATA%\ElasticManaged\{version}\elasticsearch-{version}");

var clusterConfiguration = new ClusterConfiguration(version, esHome, numberOfNodes: 2);
var clusterConfiguration = new ClusterConfiguration(version, esHome, 2);
using (var cluster = new ElasticsearchCluster(clusterConfiguration))
{
cluster.Start(new ConsoleLineWriter(), TimeSpan.FromMinutes(2));
}

Console.WriteLine("Program ended");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ namespace Elastic.Xunit.ExampleComplex
public abstract class ClusterTestClassBase<TCluster> : IClusterFixture<TCluster>
where TCluster : IEphemeralCluster<EphemeralClusterConfiguration>, IMyCluster, new()
{
protected ClusterTestClassBase(TCluster cluster) => Cluster = cluster;
public TCluster Cluster { get; }
public IElasticClient Client => Cluster.Client;

protected ClusterTestClassBase(TCluster cluster) => Cluster = cluster;
}
}
10 changes: 6 additions & 4 deletions examples/Elastic.Xunit.ExampleComplex/Clusters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

Expand All @@ -12,7 +12,8 @@ namespace Elastic.Xunit.ExampleComplex
{
internal static class EphemeralClusterExtensions
{
private static readonly ConcurrentDictionary<IEphemeralCluster, IElasticClient> Clients = new ConcurrentDictionary<IEphemeralCluster, IElasticClient>();
private static readonly ConcurrentDictionary<IEphemeralCluster, IElasticClient> Clients =
new ConcurrentDictionary<IEphemeralCluster, IElasticClient>();

public static IElasticClient GetOrAddClient(this IEphemeralCluster cluster) =>
Clients.GetOrAdd(cluster, (c) =>
Expand All @@ -36,7 +37,6 @@ protected MyClusterBase() : base(new XunitClusterConfiguration(MyRunOptions.Test
ShowElasticsearchOutputAfterStarted = false,
})
{

}

public IElasticClient Client => this.GetOrAddClient();
Expand All @@ -52,7 +52,9 @@ protected override void SeedCluster()

public class TestGenericCluster : XunitClusterBase<XunitClusterConfiguration>, IMyCluster
{
public TestGenericCluster() : base(new XunitClusterConfiguration(MyRunOptions.TestVersion)) { }
public TestGenericCluster() : base(new XunitClusterConfiguration(MyRunOptions.TestVersion))
{
}

public IElasticClient Client => this.GetOrAddClient();

Expand Down
10 changes: 6 additions & 4 deletions examples/Elastic.Xunit.ExampleComplex/Setup.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Elasticsearch.Xunit;
using Elastic.Stack.ArtifactsApi;
using Elastic.Xunit.ExampleComplex;
using Xunit;

[assembly: Xunit.TestFrameworkAttribute("Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework", "Elastic.Elasticsearch.Xunit")]
[assembly: TestFramework("Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework", "Elastic.Elasticsearch.Xunit")]
[assembly: ElasticXunitConfiguration(typeof(MyRunOptions))]

namespace Elastic.Xunit.ExampleComplex
{
/// <summary>
/// Allows us to control the custom xunit test pipeline
/// Allows us to control the custom xunit test pipeline
/// </summary>
public class MyRunOptions : ElasticXunitRunOptions
{
public static ElasticVersion TestVersion { get; } = "8.0.0-SNAPSHOT";
public MyRunOptions()
{
ClusterFilter = "";
Expand All @@ -25,5 +25,7 @@ public MyRunOptions()
IntegrationTestsMayUseAlreadyRunningNode = true;
Version = TestVersion;
}

public static ElasticVersion TestVersion { get; } = "8.0.0-SNAPSHOT";
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

Expand All @@ -12,7 +12,8 @@ namespace Elastic.Xunit.ExampleComplex
[SkipVersion("<6.3.0", "")]
public class TestWithoutClusterFixture
{
[I] public void Test()
[I]
public void Test()
{
(1 + 1).Should().Be(2);
var info = ElasticXunitRunner.CurrentCluster.GetOrAddClient().RootNodeInfo();
Expand Down
26 changes: 15 additions & 11 deletions examples/Elastic.Xunit.ExampleComplex/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

Expand All @@ -10,9 +10,12 @@ namespace Elastic.Xunit.ExampleComplex
{
public class MyTestClass : ClusterTestClassBase<TestCluster>
{
public MyTestClass(TestCluster cluster) : base(cluster) { }
public MyTestClass(TestCluster cluster) : base(cluster)
{
}

[I] public void SomeTest()
[I]
public void SomeTest()
{
var info = Client.RootNodeInfo();

Expand All @@ -21,11 +24,7 @@ [I] public void SomeTest()
Client.CreateIndex("INASda");


Client.LowLevel.Search<StringResponse>(PostData.Serializable(new
{
query = new { query_string = 1 }
}));

Client.LowLevel.Search<StringResponse>(PostData.Serializable(new {query = new {query_string = 1}}));
}
}
//
Expand All @@ -48,14 +47,19 @@ [I] public void SomeTest()
[SkipVersion("<6.2.0", "")]
public class SkipTestClass : ClusterTestClassBase<TestGenericCluster>
{
public SkipTestClass(TestGenericCluster cluster) : base(cluster) { }
public SkipTestClass(TestGenericCluster cluster) : base(cluster)
{
}

[I] public void SomeTest()
[I]
public void SomeTest()
{
var info = Client.RootNodeInfo();

info.IsValid.Should().BeTrue();
}
[U] public void UnitTest() => (1 + 1).Should().Be(2);

[U]
public void UnitTest() => (1 + 1).Should().Be(2);
}
}
10 changes: 5 additions & 5 deletions examples/Elastic.Xunit.ExampleMinimal/ExampleTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

Expand All @@ -7,23 +7,23 @@
using Elasticsearch.Net;
using FluentAssertions;
using Nest;
using Xunit;

// we need to put this assembly attribute in place for xunit to use our custom test execution pipeline
[assembly: Xunit.TestFrameworkAttribute("Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework", "Elastic.Elasticsearch.Xunit")]
[assembly: TestFramework("Elastic.Elasticsearch.Xunit.Sdk.ElasticTestFramework", "Elastic.Elasticsearch.Xunit")]

namespace Elastic.Xunit.ExampleMinimal
{
/// <summary> Declare our cluster that we want to inject into our test classes </summary>
public class MyTestCluster : XunitClusterBase
{
/// <summary>
/// We pass our configuration instance to the base class.
/// We only configure it to run version 6.2.3 here but lots of additional options are available.
/// We pass our configuration instance to the base class.
/// We only configure it to run version 6.2.3 here but lots of additional options are available.
/// </summary>
public MyTestCluster() : base(new XunitClusterConfiguration("8.0.0-SNAPSHOT") { })
{
}

}

public class ExampleTest : IClusterFixture<MyTestCluster>
Expand Down
Loading