Skip to content

Commit 08d22a5

Browse files
committed
Add test cases to unit test
1 parent 1d6ceae commit 08d22a5

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

metricbeat/module/elasticsearch/index/index.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package index
1919

2020
import (
2121
"net/url"
22+
"strings"
2223

2324
"github.com/pkg/errors"
2425

@@ -37,9 +38,9 @@ func init() {
3738
}
3839

3940
const (
40-
statsMetrics = "docs,fielddata,indexing,merge,search,segments,store,refresh,query_cache,request_cache"
41-
expandWildcardsParam = "expand_wildcards"
42-
statsPath = "/_stats/" + statsMetrics + "?filter_path=indices&" + expandWildcardsParam + "=open"
41+
statsMetrics = "docs,fielddata,indexing,merge,search,segments,store,refresh,query_cache,request_cache"
42+
expandWildcards = "expand_wildcards=open"
43+
statsPath = "/_stats/" + statsMetrics + "?filter_path=indices&" + expandWildcards
4344

4445
bulkSuffix = ",bulk"
4546
hiddenSuffix = ",hidden"
@@ -127,9 +128,7 @@ func getServicePath(esVersion common.Version) (string, error) {
127128
}
128129

129130
if !esVersion.LessThan(elasticsearch.ExpandWildcardsHiddenAvailableVersion) {
130-
ew := u.Query().Get(expandWildcardsParam)
131-
ew += hiddenSuffix
132-
u.Query().Set(expandWildcardsParam, ew)
131+
u.RawQuery = strings.Replace(u.RawQuery, expandWildcards, expandWildcards+hiddenSuffix, 1)
133132
}
134133

135134
return u.String(), nil

metricbeat/module/elasticsearch/index/index_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,29 @@ import (
2727
"github.com/stretchr/testify/require"
2828
)
2929

30-
func TestGetServiceURI(t *testing.T) {
30+
func TestGetServiceURIExpectedPath(t *testing.T) {
31+
path770 := strings.Replace(statsPath, expandWildcards, expandWildcards+hiddenSuffix, 1)
32+
path800 := strings.Replace(path770, statsMetrics, statsMetrics+bulkSuffix, 1)
33+
3134
tests := map[string]struct {
3235
esVersion *common.Version
3336
expectedPath string
3437
}{
3538
"bulk_stats_unavailable": {
36-
esVersion: common.MustNewVersion("7.9.0"),
39+
esVersion: common.MustNewVersion("7.6.0"),
3740
expectedPath: statsPath,
3841
},
3942
"bulk_stats_available": {
4043
esVersion: common.MustNewVersion("8.0.0"),
41-
expectedPath: strings.Replace(statsPath, statsMetrics, statsMetrics+",bulk", 1),
44+
expectedPath: path800,
45+
},
46+
"expand_wildcards_hidden_unavailable": {
47+
esVersion: common.MustNewVersion("7.6.0"),
48+
expectedPath: statsPath,
49+
},
50+
"expand_wildcards_hidden_available": {
51+
esVersion: common.MustNewVersion("7.7.0"),
52+
expectedPath: path770,
4253
},
4354
}
4455

0 commit comments

Comments
 (0)