tests(metricsstore): Refactor to improve coverage
This change restructures the tests in pkg/metricsstore so that the call
to `(*MetricsStore).Stop()` is moved from `TestMain` to an individual
test function to be counted for coverage. No functional changes.
Fixes
@@ -4,19 +4,11 @@ import (
"fmt"
"net/http"
"net/http/httptest"
- "os"
"testing"
tassert "github.com/stretchr/testify/assert"
)
-func TestMain(m *testing.M) {
- setup()
- code := m.Run()
- teardown()
- os.Exit(code)
-}
-
func setup() {
DefaultMetricsStore.Start(
DefaultMetricsStore.K8sAPIEventCounter,
@@ -31,7 +23,11 @@ func teardown() {
)
}
-func TestK8sAPIEventCounter(t *testing.T) {
+func TestMetricsStore(t *testing.T) {
+ setup()
+ defer teardown()
+
+ t.Run("K8sAPIEventCounter", func(t *testing.T) {
assert := tassert.New(t)
apiEventCount := 3
@@ -55,9 +51,9 @@ osm_k8s_api_event_count{namespace="foo",type="add"} %d
`, i /* api event count */)
assert.Contains(rr.Body.String(), expectedResp)
}
-}
+ })
-func TestProxyConnectCount(t *testing.T) {
+ t.Run("ProxyConnectCount", func(t *testing.T) {
assert := tassert.New(t)
proxiesConnected := 5
@@ -85,4 +81,5 @@ func TestProxyConnectCount(t *testing.T) {
osm_proxy_connect_count %d
`, proxiesConnected-proxiesDisconnected)
assert.Contains(rr.Body.String(), expectedResp)
+ })
}
