Skip to content

Commit

Permalink
Updating unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ycombinator committed May 1, 2020
1 parent 4e88e8c commit a87c509
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions metricbeat/module/elasticsearch/index/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,24 @@ import (

func TestGetServiceURI(t *testing.T) {
tests := map[string]struct {
esVersion *common.Version
expectedURI string
esVersion *common.Version
expectedPath string
}{
"bulk_stats_unavailable": {
esVersion: common.MustNewVersion("7.7.0"),
expectedURI: "http://eshost:9200" + statsPath,
esVersion: common.MustNewVersion("7.7.0"),
expectedPath: statsPath,
},
"bulk_stats_available": {
esVersion: common.MustNewVersion("7.8.0"),
expectedURI: strings.Replace("http://eshost:9200"+statsPath, statsMetrics, statsMetrics+",bulk", 1),
esVersion: common.MustNewVersion("7.8.0"),
expectedPath: strings.Replace(statsPath, statsMetrics, statsMetrics+",bulk", 1),
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
currURI := "http://eshost:9200" + statsPath
newURI, err := getServiceURI(currURI, *test.esVersion)
newURI, err := getServicePath(*test.esVersion)
require.NoError(t, err)
require.Equal(t, test.expectedURI, newURI)
require.Equal(t, test.expectedPath, newURI)
})
}
}
Expand All @@ -59,14 +58,13 @@ func TestGetServiceURIMultipleCalls(t *testing.T) {
var uri string
var err error
for i := uint(0); i < numCalls; i++ {
currURI := "http://eshost:9200" + statsPath
uri, err = getServiceURI(currURI, *common.MustNewVersion("7.8.0"))
uri, err = getServicePath(*common.MustNewVersion("7.8.0"))
if err != nil {
return false
}
}

return err == nil && uri == strings.Replace("http://eshost:9200"+statsPath, statsMetrics, statsMetrics+",bulk", 1)
return err == nil && uri == strings.Replace(statsPath, statsMetrics, statsMetrics+",bulk", 1)
}, nil)
require.NoError(t, err)
}

0 comments on commit a87c509

Please sign in to comment.