remove default `_all` for `type` and `index` if these are missing in REST tests
If a type or path is missing in the REST test yaml file, it is automatically replaced with _all. This makes it hard to test changes in the api, for example adding the possibility to leave the index blank in addition to _all and * in the uri. closes #4657
This commit is contained in:
parent
e6f83248a2
commit
216c814a7f
|
@ -18,8 +18,7 @@
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"required" : false,
|
"required" : true,
|
||||||
"default" : "_all",
|
|
||||||
"description" : "The type of the document (use `_all` to fetch the first document matching the ID across all types)"
|
"description" : "The type of the document (use `_all` to fetch the first document matching the ID across all types)"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"required" : false,
|
"required" : true,
|
||||||
"default" : "_all",
|
|
||||||
"description" : "The type of the document (use `_all` to fetch the first document matching the ID across all types)"
|
"description" : "The type of the document (use `_all` to fetch the first document matching the ID across all types)"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"type" : "string",
|
"type" : "string",
|
||||||
"required" : false,
|
"required" : true,
|
||||||
"default" : "_all",
|
|
||||||
"description" : "The type of the document; use `_all` to fetch the first document matching the ID across all types"
|
"description" : "The type of the document; use `_all` to fetch the first document matching the ID across all types"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
"parts": {
|
"parts": {
|
||||||
"index": {
|
"index": {
|
||||||
"type" : "list",
|
"type" : "list",
|
||||||
"default" : "_all",
|
|
||||||
"description" : "A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices"
|
"description" : "A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices"
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
- do:
|
- do:
|
||||||
exists:
|
exists:
|
||||||
index: test_1
|
index: test_1
|
||||||
|
type: _all
|
||||||
id: 1
|
id: 1
|
||||||
|
|
||||||
- is_true: ''
|
- is_true: ''
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
- do:
|
- do:
|
||||||
get:
|
get:
|
||||||
index: test_1
|
index: test_1
|
||||||
|
type: _all
|
||||||
id: 中文
|
id: 中文
|
||||||
|
|
||||||
- match: { _index: test_1 }
|
- match: { _index: test_1 }
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
- do:
|
- do:
|
||||||
get:
|
get:
|
||||||
index: test_1
|
index: test_1
|
||||||
|
type: _all
|
||||||
id: 1
|
id: 1
|
||||||
|
|
||||||
- match: { _index: test_1 }
|
- match: { _index: test_1 }
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
- do:
|
- do:
|
||||||
get_source:
|
get_source:
|
||||||
index: test_1
|
index: test_1
|
||||||
|
type: _all
|
||||||
id: 1
|
id: 1
|
||||||
|
|
||||||
- match: { '': { foo: bar } }
|
- match: { '': { foo: bar } }
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
- do:
|
- do:
|
||||||
get_source:
|
get_source:
|
||||||
index: test_1
|
index: test_1
|
||||||
|
type: _all
|
||||||
id: 1
|
id: 1
|
||||||
|
|
||||||
- match: { '': { foo: bar } }
|
- match: { '': { foo: bar } }
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
search:
|
search:
|
||||||
type: test
|
index: _all
|
||||||
|
type: test
|
||||||
body:
|
body:
|
||||||
query:
|
query:
|
||||||
match:
|
match:
|
||||||
|
|
|
@ -36,8 +36,6 @@ import java.util.regex.Pattern;
|
||||||
*/
|
*/
|
||||||
public class RestApi {
|
public class RestApi {
|
||||||
|
|
||||||
private static final String ALL = "_all";
|
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private List<String> methods = Lists.newArrayList();
|
private List<String> methods = Lists.newArrayList();
|
||||||
private List<String> paths = Lists.newArrayList();
|
private List<String> paths = Lists.newArrayList();
|
||||||
|
@ -123,18 +121,18 @@ public class RestApi {
|
||||||
RestPath matchingRestPath = findMatchingRestPath(pathParams.keySet());
|
RestPath matchingRestPath = findMatchingRestPath(pathParams.keySet());
|
||||||
String path = matchingRestPath.path;
|
String path = matchingRestPath.path;
|
||||||
for (Map.Entry<String, String> paramEntry : matchingRestPath.params.entrySet()) {
|
for (Map.Entry<String, String> paramEntry : matchingRestPath.params.entrySet()) {
|
||||||
//replace path placeholders with actual values
|
// replace path placeholders with actual values
|
||||||
String value = pathParams.get(paramEntry.getValue());
|
String value = pathParams.get(paramEntry.getValue());
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
//there might be additional placeholder to replace, not available as input params
|
// if a value is missing, we got the wrong path or the test was
|
||||||
//it can only be {index} or {type} to be replaced with _all
|
// specified incorrectly
|
||||||
if (paramEntry.getValue().equals("index") || paramEntry.getValue().equals("type")) {
|
// TODO: What if more than one path exists? for example: PUT
|
||||||
value = ALL;
|
// index/type/_mapping vs. PUT index/_maping/type? Should we
|
||||||
} else {
|
// randomize?
|
||||||
throw new IllegalArgumentException("path [" + path + "] contains placeholders that weren't replaced with proper values");
|
throw new IllegalArgumentException("parameter [" + paramEntry.getValue() + "] missing");
|
||||||
}
|
} else {
|
||||||
|
path = path.replace(paramEntry.getKey(), value);
|
||||||
}
|
}
|
||||||
path = path.replace(paramEntry.getKey(), value);
|
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue