-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// mongodb_exporter | ||
// Copyright (C) 2017 Percona LLC | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
package exporter | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/percona/mongodb_exporter/internal/tu" | ||
) | ||
|
||
func TestReplsetConfigCollector(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) | ||
defer cancel() | ||
|
||
client := tu.DefaultTestClient(ctx, t) | ||
|
||
ti := labelsGetterMock{} | ||
|
||
c := &replSetGetConfigCollector{ | ||
ctx: ctx, | ||
client: client, | ||
logger: logrus.New(), | ||
topologyInfo: ti, | ||
} | ||
|
||
// The last \n at the end of this string is important | ||
expected := strings.NewReader(` | ||
# HELP mongodb_cfg_protocolVersion cfg. | ||
# TYPE mongodb_cfg_protocolVersion untyped | ||
mongodb_cfg_protocolVersion 1` + "\n") | ||
// Filter metrics for 2 reasons: | ||
// 1. The result is huge | ||
// 2. We need to check against know values. Don't use metrics that return counters like uptime | ||
// or counters like the number of transactions because they won't return a known value to compare | ||
filter := []string{ | ||
"mongodb_cfg_protocolVersion", | ||
} | ||
err := testutil.CollectAndCompare(c, expected, filter...) | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestReplsetConfigCollectorNoSharding(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) | ||
defer cancel() | ||
|
||
client := tu.TestClient(ctx, tu.MongoDBStandAlonePort, t) | ||
|
||
ti := labelsGetterMock{} | ||
|
||
c := &replSetGetConfigCollector{ | ||
ctx: ctx, | ||
client: client, | ||
topologyInfo: ti, | ||
} | ||
|
||
expected := strings.NewReader(``) | ||
err := testutil.CollectAndCompare(c, expected) | ||
assert.NoError(t, err) | ||
} |