-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
7f8ebea
commit 8c34886
Showing
3 changed files
with
140 additions
and
1 deletion.
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,89 @@ | ||
package collector | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/go-kit/log" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestNewDigicertCollectorWithoutMockedData(t *testing.T) { | ||
|
||
logger := log.NewNopLogger() | ||
digicertURL := "https://digicert.com" | ||
digicertAPIKey := "API_KEY" | ||
|
||
// Create a new DigicertCollector | ||
collector, err := NewDigicertCollector(logger, digicertURL, digicertAPIKey, true) | ||
|
||
assert.NoError(t, err) | ||
assert.False(t, collector.useMockedData) | ||
} | ||
|
||
func TestNewDigicertCollectorWithMockedData(t *testing.T) { | ||
|
||
logger := log.NewNopLogger() | ||
digicertURL := "" | ||
digicertAPIKey := "" | ||
|
||
// Create a new DigicertCollector | ||
collector, err := NewDigicertCollector(logger, digicertURL, digicertAPIKey, true) | ||
|
||
assert.NoError(t, err) | ||
assert.True(t, collector.useMockedData) | ||
} | ||
|
||
func TestUpdateMetricsApiDown(t *testing.T) { | ||
logger := log.NewNopLogger() | ||
digicertURL := "https://digicert.com" | ||
digicertAPIKey := "test" | ||
|
||
// Create a new DigicertCollector | ||
collector, err := NewDigicertCollector(logger, digicertURL, digicertAPIKey, true) | ||
assert.NoError(t, err) | ||
|
||
promChan := make(chan prometheus.Metric) | ||
|
||
go collector.UpdateMetrics(promChan) | ||
|
||
expected := strings.NewReader( | ||
`# HELP digicert_api_up Was the last Digicert API query successful. | ||
# TYPE digicert_api_up gauge | ||
digicert_api_up 0 | ||
`) | ||
|
||
err = testutil.CollectAndCompare( | ||
collector, | ||
expected, | ||
"digicert_api_up", | ||
) | ||
} | ||
|
||
func TestUpdateMetricsUse(t *testing.T) { | ||
logger := log.NewNopLogger() | ||
digicertURL := "" | ||
digicertAPIKey := "" | ||
|
||
// Create a new DigicertCollector | ||
collector, err := NewDigicertCollector(logger, digicertURL, digicertAPIKey, true) | ||
assert.NoError(t, err) | ||
|
||
promChan := make(chan prometheus.Metric) | ||
|
||
go collector.UpdateMetrics(promChan) | ||
|
||
expected := strings.NewReader( | ||
`# HELP digicert_api_up Was the last Digicert API query successful. | ||
# TYPE digicert_api_up gauge | ||
digicert_api_up 0 | ||
`) | ||
|
||
err = testutil.CollectAndCompare( | ||
collector, | ||
expected, | ||
"digicert_api_up", | ||
) | ||
} |
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
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