-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 添加favicon图片 * firset * 修改 * 撤销 * add open search * add open search * add open * elasticsearch * 修改路径错误 * 修改路径错误 * 修改路径错误 撤回 * 修改路径错误 撤回 * 添加测试方法 * 格式化 * 单元测试方法 * 重新提交 --------- Co-authored-by: 王飞 <fei.wang@xgo.one>
- Loading branch information
1 parent
128be66
commit e1fc3f6
Showing
5 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,5 @@ cassandra-driver | |
httpx | ||
OpenAI | ||
elasticsearch==8.14.0 | ||
opensearch_py==2.6.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import json | ||
import unittest | ||
from unittest.mock import patch, Mock | ||
from sql.engines import ResultSet, ReviewSet | ||
from sql.engines.elasticsearch import OpenSearchEngine | ||
from sql.models import Instance | ||
|
||
|
||
class TestOpenSearchEngine(unittest.TestCase): | ||
def setUp(self): | ||
# 创建一个模拟的 instance 对象,包含必要的属性 | ||
self.mock_instance = Instance() | ||
self.mock_instance.host = "localhost" | ||
self.mock_instance.port = 9200 | ||
self.mock_instance.user = "user" | ||
self.mock_instance.password = "pass" | ||
self.mock_instance.is_ssl = True | ||
|
||
# 初始化 OpenSearchEngine | ||
self.engine = OpenSearchEngine(instance=self.mock_instance) | ||
|
||
@patch("sql.engines.elasticsearch.OpenSearch") | ||
def test_get_all_databases(self, mockElasticsearch): | ||
mock_conn = Mock() | ||
mock_conn.indices.get_alias.return_value = { | ||
"test__index1": {}, | ||
"test__index2": {}, | ||
".kibana_2": {}, | ||
".internal.index": {}, | ||
} | ||
mockElasticsearch.return_value = mock_conn | ||
|
||
result = self.engine.get_all_databases() | ||
expected_result = [ | ||
"other", | ||
"system", | ||
"system_internal", | ||
"system_kibana", | ||
"test", | ||
] | ||
self.assertEqual(result.rows, expected_result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters