Skip to content

Commit 7ce088f

Browse files
author
Leonid Orsulic
committed
add test for custom request with query items
1 parent 1c7d6fd commit 7ce088f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Tests/ElasticsearchNIOClientTests/ElasticsearchNIOClientTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,36 @@ class ElasticSearchIntegrationTests: XCTestCase {
597597
XCTAssertEqual(count["value"] as! Double, 50.5)
598598
}
599599

600+
func testCustomRequestWithQueryItems() throws {
601+
// create index
602+
let mappings: [String: Any] = [
603+
"properties": [
604+
"keyword_field": [
605+
"type": "keyword",
606+
"fields": [
607+
"test": [
608+
"type": "text"
609+
]
610+
]
611+
]
612+
]
613+
]
614+
let settings: [String: Any] = ["number_of_shards": 3]
615+
let createResponse = try client.createIndex(indexName, mappings: mappings, settings: settings).wait()
616+
XCTAssertEqual(createResponse.acknowledged, true)
617+
618+
// get indices in json format
619+
struct ESGetSingleIndexResponse: Decodable {
620+
let index: String
621+
}
622+
let resultData = try client.custom("/_cat/indices", queryItems: [URLQueryItem(name: "format", value: "json")], method: .GET, body: "".data(using: .utf8)!).wait()
623+
let results = try JSONDecoder().decode([ESGetSingleIndexResponse].self, from: resultData)
624+
XCTAssertNotNil(results.map { $0.index }.first { $0 == indexName })
625+
626+
// delete index
627+
let deleteResponse = try client.deleteIndex(self.indexName).wait()
628+
XCTAssertEqual(deleteResponse.acknowledged, true)
629+
}
600630

601631
func testCustomSearchWithDataQuery() throws {
602632
for index in 1...100 {

0 commit comments

Comments
 (0)