Skip to content

Commit 51f9e3d

Browse files
committed
all but one tests still succeed
1 parent b99d86a commit 51f9e3d

40 files changed

+1214
-54
lines changed

src/CodeGeneration/CodeGeneration.YamlTestsRunner/Extensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public static string SerializeToAnonymousObject(this object o, string indentatio
133133
//needs some recursive regex love perhaps in the future
134134
anon = Regex.Replace(anon, @"(index|discovery)\.([^=]+)=([^\r\n,]+)", " { \"$1.$2\", $3 }", RegexOptions.Multiline);
135135
anon = Regex.Replace(anon, @"new \{(\r\n\s+\{ "")(index|discovery)", "new Dictionary<string, object> {$1$2", RegexOptions.Multiline);
136+
137+
anon = Regex.Replace(anon, @"= (""?$)(.+)(""| )", "= $1", RegexOptions.Multiline);
136138
return anon;
137139
}
138140

src/CodeGeneration/CodeGeneration.YamlTestsRunner/YamlTestsGenerator.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using CodeGeneration.YamlTestsRunner.Domain;
1313
using CsQuery;
1414
using CsQuery.ExtensionMethods.Internal;
15+
using FubuCore.Util;
1516
using FubuCsProjFile;
1617
using ShellProgressBar;
1718
using Xipton.Razor;
@@ -81,6 +82,18 @@ public static YamlSpecification GetYamlTestSpecification(bool useCache = false)
8182
};
8283
}
8384

85+
/// <summary>
86+
/// TODO: these tests contain object definitions that the ToAnonymous barfs on.
87+
/// We skip them for now but we should fix the generator so that it generates dictionaries
88+
/// in this case.
89+
/// </summary>
90+
private static string[] SkipTests = new string[]
91+
{
92+
"40_search_request_template.yaml",
93+
"30_template_query_execution.yaml",
94+
"19_nested.yaml",
95+
};
96+
8497
private static IList<YamlDefinition> GetFolderFiles(string folder, bool useCache = false)
8598
{
8699
var url = useCache ? LocalUri(folder + ".html") : _listingUrl + "/" + folder;
@@ -97,6 +110,9 @@ where fileName.EndsWith(".yaml")
97110
foreach (var file in files)
98111
{
99112
++i;
113+
if (SkipTests.Contains(file))
114+
continue;
115+
100116
var yaml = GetYamlFile(folder, useCache, file);
101117
var parsed = ParseYaml(yaml).ToList();
102118
var prefix = Regex.Replace(file, @"^(\d+).*$", "$1");

src/Tests/Elasticsearch.Net.Integration.Yaml/Elasticsearch.Net.Integration.Yaml.csproj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
44
<PropertyGroup>
@@ -78,17 +78,21 @@
7878
<Compile Include="cat.aliases\10_basic.yaml.cs" />
7979
<Compile Include="cat.allocation\10_basic.yaml.cs" />
8080
<Compile Include="cat.count\10_basic.yaml.cs" />
81+
<Compile Include="cat.recovery\10_basic.yaml.cs" />
8182
<Compile Include="cat.shards\10_basic.yaml.cs" />
8283
<Compile Include="cat.thread_pool\10_basic.yaml.cs" />
8384
<Compile Include="cluster.pending_tasks\10_basic.yaml.cs" />
8485
<Compile Include="cluster.put_settings\10_basic.yaml.cs" />
8586
<Compile Include="cluster.reroute\10_basic.yaml.cs" />
87+
<Compile Include="cluster.reroute\11_explain.yaml.cs" />
8688
<Compile Include="cluster.state\10_basic.yaml.cs" />
8789
<Compile Include="cluster.state\20_filtering.yaml.cs" />
8890
<Compile Include="create\10_with_id.yaml.cs" />
8991
<Compile Include="create\15_without_id.yaml.cs" />
9092
<Compile Include="create\30_internal_version.yaml.cs" />
9193
<Compile Include="create\35_external_version.yaml.cs" />
94+
<Compile Include="create\36_external_gte_version.yaml.cs" />
95+
<Compile Include="create\37_force_version.yaml.cs" />
9296
<Compile Include="create\40_routing.yaml.cs" />
9397
<Compile Include="create\50_parent.yaml.cs" />
9498
<Compile Include="create\55_parent_with_routing.yaml.cs" />
@@ -98,6 +102,8 @@
98102
<Compile Include="delete\10_basic.yaml.cs" />
99103
<Compile Include="delete\20_internal_version.yaml.cs" />
100104
<Compile Include="delete\25_external_version.yaml.cs" />
105+
<Compile Include="delete\26_external_gte_version.yaml.cs" />
106+
<Compile Include="delete\27_force_version.yaml.cs" />
101107
<Compile Include="delete\30_routing.yaml.cs" />
102108
<Compile Include="delete\40_parent.yaml.cs" />
103109
<Compile Include="delete\45_parent_with_routing.yaml.cs" />
@@ -135,6 +141,8 @@
135141
<Compile Include="index\20_optype.yaml.cs" />
136142
<Compile Include="index\30_internal_version.yaml.cs" />
137143
<Compile Include="index\35_external_version.yaml.cs" />
144+
<Compile Include="index\36_external_gte_version.yaml.cs" />
145+
<Compile Include="index\37_force_version.yaml.cs" />
138146
<Compile Include="index\40_routing.yaml.cs" />
139147
<Compile Include="index\50_parent.yaml.cs" />
140148
<Compile Include="index\55_parent_with_routing.yaml.cs" />
@@ -182,11 +190,13 @@
182190
<Compile Include="indices.put_warmer\10_basic.yaml.cs" />
183191
<Compile Include="indices.put_warmer\20_aliases.yaml.cs" />
184192
<Compile Include="indices.put_warmer\all_path_options.yaml.cs" />
193+
<Compile Include="indices.recovery\10_basic.yaml.cs" />
185194
<Compile Include="indices.segments\10_basic.yaml.cs" />
186195
<Compile Include="indices.snapshot_index\10_basic.yaml.cs" />
187196
<Compile Include="indices.stats\10_basic.yaml.cs" />
188197
<Compile Include="indices.status\10_basic.yaml.cs" />
189198
<Compile Include="indices.update_aliases\10_basic.yaml.cs" />
199+
<Compile Include="indices.update_aliases\20_routing.yaml.cs" />
190200
<Compile Include="indices.validate_query\10_basic.yaml.cs" />
191201
<Compile Include="info\10_info.yaml.cs" />
192202
<Compile Include="info\20_lucene_version.yaml.cs" />
@@ -210,6 +220,7 @@
210220
<Compile Include="percolate\15_new.yaml.cs" />
211221
<Compile Include="percolate\16_existing_doc.yaml.cs" />
212222
<Compile Include="percolate\17_empty.yaml.cs" />
223+
<Compile Include="percolate\18_highligh_with_query.yaml.cs" />
213224
<Compile Include="ping\10_ping.yaml.cs" />
214225
<Compile Include="Properties\AssemblyInfo.cs" />
215226
<Compile Include="scroll\10_basic.yaml.cs" />

src/Tests/Elasticsearch.Net.Integration.Yaml/YamlTestsBase.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ protected void IsMatch(object o, object value)
277277
var v = Convert.ToDecimal(value);
278278
Assert.AreEqual(v,i);
279279
}
280+
else if (o is bool)
281+
{
282+
bool vb;
283+
if (!bool.TryParse(value.ToString().ToCamelCase(), out vb))
284+
Assert.Fail(value.ToString() + " is not a bool");
285+
Assert.AreEqual(o, vb);
286+
}
280287
else if (o is double)
281288
{
282289
var i = (double)o;
@@ -313,8 +320,9 @@ protected void IsMatch(object o, object value)
313320
else if (v.StartsWith("/"))
314321
{
315322
var re = Regex.Replace(v, @"(^[\s\r\n]*?\/|\/[\s\r\n]*?$)", "");
316-
var r = Encoding.UTF8.GetString(this._status.ResponseRaw);
317-
Assert.IsTrue(Regex.IsMatch(r, re, RegexOptions.IgnorePatternWhitespace));
323+
if (value is byte[])
324+
s = Encoding.UTF8.GetString(this._status.ResponseRaw);
325+
Assert.IsTrue(Regex.IsMatch(s, re, RegexOptions.IgnorePatternWhitespace));
318326
}
319327
else Assert.AreEqual(s, v);
320328
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Specialized;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using NUnit.Framework;
8+
9+
10+
namespace Elasticsearch.Net.Integration.Yaml.CatRecovery1
11+
{
12+
public partial class CatRecovery1YamlTests
13+
{
14+
15+
public class CatRecovery110BasicYamlBase : YamlTestsBase
16+
{
17+
public CatRecovery110BasicYamlBase() : base()
18+
{
19+
20+
}
21+
}
22+
23+
24+
[NCrunch.Framework.ExclusivelyUses("ElasticsearchYamlTests")]
25+
public class TestCatRecoveryOutput2Tests : CatRecovery110BasicYamlBase
26+
{
27+
[Test]
28+
public void TestCatRecoveryOutput2Test()
29+
{
30+
31+
//do cat.recovery
32+
this.Do(()=> _client.CatRecovery());
33+
34+
//match this._status:
35+
this.IsMatch(this._status, @"/^$/
36+
");
37+
38+
//do index
39+
_body = new {
40+
foo= "bar"
41+
};
42+
this.Do(()=> _client.Index("index1", "type1", "1", _body, nv=>nv
43+
.AddQueryString("refresh", @"true")
44+
));
45+
46+
//do cluster.health
47+
this.Do(()=> _client.ClusterHealth(nv=>nv
48+
.AddQueryString("wait_for_status", @"yellow")
49+
));
50+
51+
//do cat.recovery
52+
this.Do(()=> _client.CatRecovery());
53+
54+
//match this._status:
55+
this.IsMatch(this._status, @"/^(index1 \s+ \d+ \s+ \d+ \s+
56+
(gateway|replica|snapshot|relocating) \s+
57+
(init|index|start|translog|finalize|done) \s+
58+
([\w/.-])+ \s+
59+
([\w/.-])+ \s+
60+
([\w/.-])+ \s+
61+
([\w/.-])+ \s+
62+
\d+ \s+ \d+\.\d+\% \s+ \d+ \s+ \d+\.\d+\% \s+ \n?)
63+
{1,}$/
64+
");
65+
66+
}
67+
}
68+
}
69+
}
70+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Specialized;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using NUnit.Framework;
8+
9+
10+
namespace Elasticsearch.Net.Integration.Yaml.ClusterReroute2
11+
{
12+
public partial class ClusterReroute2YamlTests
13+
{
14+
15+
public class ClusterReroute211ExplainYamlBase : YamlTestsBase
16+
{
17+
public ClusterReroute211ExplainYamlBase() : base()
18+
{
19+
20+
//do indices.create
21+
_body = new {
22+
settings= new {
23+
number_of_shards= "1",
24+
number_of_replicas= "0"
25+
}
26+
};
27+
this.Do(()=> _client.IndicesCreate("test_index", _body));
28+
29+
//do cluster.health
30+
this.Do(()=> _client.ClusterHealth(nv=>nv
31+
.AddQueryString("wait_for_status", @"green")
32+
));
33+
34+
}
35+
}
36+
37+
38+
[NCrunch.Framework.ExclusivelyUses("ElasticsearchYamlTests")]
39+
public class ExplainApiWithEmptyCommandList2Tests : ClusterReroute211ExplainYamlBase
40+
{
41+
[Test]
42+
public void ExplainApiWithEmptyCommandList2Test()
43+
{
44+
45+
//do cluster.reroute
46+
_body = new {
47+
commands= new string[] {}
48+
};
49+
this.Do(()=> _client.ClusterReroute(_body, nv=>nv
50+
.AddQueryString("explain", @"true")
51+
.AddQueryString("dry_run", @"true")
52+
));
53+
54+
//match _response.explanations:
55+
this.IsMatch(_response.explanations, new string[] {});
56+
57+
}
58+
}
59+
60+
[NCrunch.Framework.ExclusivelyUses("ElasticsearchYamlTests")]
61+
public class ExplainApiForNonExistantNodeShard3Tests : ClusterReroute211ExplainYamlBase
62+
{
63+
[Test]
64+
public void ExplainApiForNonExistantNodeShard3Test()
65+
{
66+
67+
//do cluster.state
68+
this.Do(()=> _client.ClusterState("master_node"));
69+
70+
//set node_id = _response.master_node;
71+
var node_id = _response.master_node;
72+
73+
//do cluster.reroute
74+
_body = new {
75+
commands= new [] {
76+
new {
77+
cancel= new {
78+
index= "test_index",
79+
shard= "9",
80+
node= "$node_id"
81+
}
82+
}
83+
}
84+
};
85+
this.Do(()=> _client.ClusterReroute(_body, nv=>nv
86+
.AddQueryString("explain", @"true")
87+
.AddQueryString("dry_run", @"true")
88+
));
89+
90+
//match _response.explanations[0].command:
91+
this.IsMatch(_response.explanations[0].command, @"cancel");
92+
93+
//match _response.explanations[0].parameters:
94+
this.IsMatch(_response.explanations[0].parameters, new {
95+
index= "test_index",
96+
shard= "9",
97+
node= "$node_id",
98+
allow_primary= "false"
99+
});
100+
101+
//match _response.explanations[0].decisions[0].decider:
102+
this.IsMatch(_response.explanations[0].decisions[0].decider, @"cancel_allocation_command");
103+
104+
//match _response.explanations[0].decisions[0].decision:
105+
this.IsMatch(_response.explanations[0].decisions[0].decision, @"NO");
106+
107+
//is_true _response.explanations[0].decisions[0].explanation;
108+
this.IsTrue(_response.explanations[0].decisions[0].explanation);
109+
110+
}
111+
}
112+
}
113+
}
114+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.Specialized;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using NUnit.Framework;
8+
9+
10+
namespace Elasticsearch.Net.Integration.Yaml.Create5
11+
{
12+
public partial class Create5YamlTests
13+
{
14+
15+
16+
[NCrunch.Framework.ExclusivelyUses("ElasticsearchYamlTests")]
17+
public class ExternalVersion1Tests : YamlTestsBase
18+
{
19+
[Test]
20+
public void ExternalVersion1Test()
21+
{
22+
23+
//do create
24+
_body = new {
25+
foo= "bar"
26+
};
27+
this.Do(()=> _client.Index("test_1", "test", "1", _body, nv=>nv
28+
.AddQueryString("version_type", @"external_gte")
29+
.AddQueryString("version", 5)
30+
.AddQueryString("op_type", @"create")
31+
));
32+
33+
//match _response._version:
34+
this.IsMatch(_response._version, 5);
35+
36+
//do create
37+
_body = new {
38+
foo= "bar"
39+
};
40+
this.Do(()=> _client.Index("test_1", "test", "1", _body, nv=>nv
41+
.AddQueryString("version_type", @"external_gte")
42+
.AddQueryString("version", 5)
43+
.AddQueryString("op_type", @"create")
44+
), shouldCatch: @"conflict");
45+
46+
//do create
47+
_body = new {
48+
foo= "bar"
49+
};
50+
this.Do(()=> _client.Index("test_1", "test", "1", _body, nv=>nv
51+
.AddQueryString("version_type", @"external_gte")
52+
.AddQueryString("version", 6)
53+
.AddQueryString("op_type", @"create")
54+
), shouldCatch: @"conflict");
55+
56+
}
57+
}
58+
}
59+
}
60+

0 commit comments

Comments
 (0)