Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch committed Jan 27, 2022
1 parent 25844b6 commit 10dbb06
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion libbeat/idxmgmt/std.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (s *ilmIndexSelector) Select(evt *beat.Event) (string, error) {
return idx, err
}

func (s ilmIndexSelector) IsAlias() bool { return s.st.withILM.Load() }
func (s ilmIndexSelector) IsAlias() bool { return true }

func (s indexSelector) Select(evt *beat.Event) (string, error) {
if idx := getEventCustomIndex(evt, s.beatInfo); idx != "" {
Expand Down
31 changes: 31 additions & 0 deletions libbeat/outputs/elasticsearch/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ func TestBulkEncodeEvents(t *testing.T) {
ilmConfig *common.Config
isAlias bool
events []common.MapStr
metas []common.MapStr
}{
"6.x": {
version: "6.8.0",
Expand Down Expand Up @@ -446,6 +447,31 @@ func TestBulkEncodeEvents(t *testing.T) {
isAlias: true,
events: []common.MapStr{{"message": "test"}},
},
"latest with ILM but to monitoring index": {
version: version.GetDefaultVersion(),
docType: "",
config: common.MapStr{},
ilmConfig: common.NewConfig(),
events: []common.MapStr{{"message": "test"}},
metas: []common.MapStr{common.MapStr{"index": ".monitoring-index"}},
},
"latest with ILM but to raw_index": {
version: version.GetDefaultVersion(),
docType: "",
config: common.MapStr{},
ilmConfig: common.NewConfig(),
events: []common.MapStr{{"message": "test"}},
metas: []common.MapStr{common.MapStr{"index": "my-raw-index"}},
},
"latest with ILM and to alias": {
version: version.GetDefaultVersion(),
docType: "",
config: common.MapStr{},
ilmConfig: common.NewConfig(),
isAlias: true,
events: []common.MapStr{{"message": "test"}},
metas: []common.MapStr{common.MapStr{"alias": "my-alias"}},
},
"latest without ILM": {
version: version.GetDefaultVersion(),
docType: "",
Expand All @@ -472,10 +498,15 @@ func TestBulkEncodeEvents(t *testing.T) {

events := make([]publisher.Event, len(test.events))
for i, fields := range test.events {
var meta common.MapStr
if len(test.metas) > i {
meta = test.metas[i]
}
events[i] = publisher.Event{
Content: beat.Event{
Timestamp: time.Now(),
Fields: fields,
Meta: meta,
},
}
}
Expand Down

0 comments on commit 10dbb06

Please sign in to comment.