diff --git a/internalContext.go b/internalContext.go index 5008ef0..23cbdaa 100644 --- a/internalContext.go +++ b/internalContext.go @@ -26,7 +26,7 @@ func (receiver *internalContext) Original() *elastic.Client { func RegisterInternalContext(name string, configString string) { config := configure.ParseString[EsConfig](configString) if config.Server == "" { - panic("[farseer.yaml]ElasticSearch." + name + ".ConsumerServer,没有正确配置") + panic("[farseer.yaml]ElasticSearch." + name + ".Server,没有正确配置") } if config.RefreshInterval == 0 { config.RefreshInterval = 1 diff --git a/test/esContext_test.go b/test/esContext_test.go index bf4bd94..8f0f562 100644 --- a/test/esContext_test.go +++ b/test/esContext_test.go @@ -26,7 +26,7 @@ type UserPO struct { func TestNewContext(t *testing.T) { // 设置配置默认值,模拟配置文件 - configure.SetDefault("ElasticSearch.test", "ConsumerServer=http://es:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.test", "Server=http://es:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("test") context.User.SetIndexName("user_index_01", "user_index_alis_01") assert.Equal(t, "user_index_01", context.User.GetIndexName()) @@ -50,7 +50,7 @@ func TestInitContext(t *testing.T) { fmt.Printf("%d-%02d-%02d %02d:%02d:%02d\n", year, month, day, hour, minute, second) flog.Println(year, month, day, hour, minute, second) // 设置配置默认值,模拟配置文件 - configure.SetDefault("ElasticSearch.test", "ConsumerServer=http://es:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.test", "Server=http://es:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") var context TestEsContext elasticSearch.InitContext(&context, "test") diff --git a/test/indexSet_test.go b/test/indexSet_test.go index 7b12c5d..0451afb 100644 --- a/test/indexSet_test.go +++ b/test/indexSet_test.go @@ -42,7 +42,7 @@ func TestIndexSet_Init(t *testing.T) { } func TestIndexSet_Insert(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") po := UserPO{Name: "小强", Age: 10, Id: 12} err := context.User.Insert(po) @@ -50,7 +50,7 @@ func TestIndexSet_Insert(t *testing.T) { } func TestIndexSet_InsertArray(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") var array []UserPO po := UserPO{Name: "小强2", Age: 10, Id: 13} @@ -60,7 +60,7 @@ func TestIndexSet_InsertArray(t *testing.T) { } func TestIndexSet_InsertList(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") list := collections.NewList(UserPO{Name: "小丽", Age: 20, Id: 2}, UserPO{Name: "小王", Age: 30, Id: 3}) err := context.User.InsertList(list) @@ -68,7 +68,7 @@ func TestIndexSet_InsertList(t *testing.T) { } func TestIndexSet_Select(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") context.User.SetIndexName("user_select_index_01", "user_select_alis_index_01") list := collections.NewList(UserPO{Name: "小丽", Age: 20, Id: 2}, UserPO{Name: "小王", Age: 30, Id: 3}) @@ -80,35 +80,35 @@ func TestIndexSet_Select(t *testing.T) { } } func TestIndexSet_Asc(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") getList := context.User.Asc("Id").ToList() assert.Equal(t, getList.First().Name, "小丽") } func TestIndexSet_Desc(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") list := context.User.Desc("Id").ToList() assert.Equal(t, list.First().Name, "小王") } func TestIndexSet_GetIndexName(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") name := context.User.GetIndexName() assert.Equal(t, name, context.User.GetIndexName()) } func TestIndexSet_ToList(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") list := context.User.ToList() assert.Equal(t, list.Count(), 5) } func TestIndexSet_ToPageList(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") context.User.SetIndexName("user_page_index_01", "user_page_alis_index_01") list := collections.NewList(UserPO{Name: "小丽", Age: 20, Id: 2}, UserPO{Name: "小王", Age: 30, Id: 3}, UserPO{Name: "小王2", Age: 30, Id: 3}) @@ -118,7 +118,7 @@ func TestIndexSet_ToPageList(t *testing.T) { } func TestIndexSet_Where(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") po := UserPO{Name: "小王", Age: 30, Id: 14} _ = context.User.Insert(po) @@ -126,7 +126,7 @@ func TestIndexSet_Where(t *testing.T) { assert.Equal(t, list2.First().Name, "小王") } func TestIndexSet_DelIndex(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") context.User.SetIndexName("user_111", "user_alis_111") po := UserPO{Name: "小强", Age: 10, Id: 12} @@ -135,7 +135,7 @@ func TestIndexSet_DelIndex(t *testing.T) { assert.Equal(t, err, nil) } func TestIndexSet_DelData(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") po := UserPO{Name: "小强", Age: 10, Id: 888} _ = context.User.Insert(po) @@ -143,7 +143,7 @@ func TestIndexSet_DelData(t *testing.T) { assert.Equal(t, err, nil) } func TestIndexSet_SetAliasesName(t *testing.T) { - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") context := elasticSearch.NewContext[TestEsContext]("log_es") context.User.SetIndexName("test_11", "test_alis_11") _ = context.User.SetAliasesName("test_alis_22") @@ -152,9 +152,9 @@ func TestIndexSet_SetAliasesName(t *testing.T) { assert.Equal(t, err, nil) } func TestIndexSet_Data(t *testing.T) { - //configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + //configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") //context := elasticSearch.NewContext[TestEsContext]("log_es") - //context.User.esContext.esConfig.ConsumerServer = "0.0.0.0" + //context.User.esContext.esConfig.Server = "0.0.0.0" //assert.Panics(t, func() { // _ = context.User.SetAliasesName("test_alis_223") //}) diff --git a/test/init_test.go b/test/init_test.go index d6bf897..106fc13 100644 --- a/test/init_test.go +++ b/test/init_test.go @@ -8,6 +8,6 @@ import ( func init() { // 设置配置默认值,模拟配置文件 - configure.SetDefault("ElasticSearch.log_es", "ConsumerServer=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") + configure.SetDefault("ElasticSearch.log_es", "Server=http://localhost:9200,Username=es,Password=123456,ReplicasCount=1,ShardsCount=1,RefreshInterval=5,IndexFormat=yyyy_MM") fs.Initialize[elasticSearch.Module]("test es") }