Skip to content

Commit

Permalink
tlsprom: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
abursavich committed Mar 24, 2020
1 parent e345759 commit 6115b1a
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tlsprom/tlsprom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ import (
"github.com/prometheus/client_golang/prometheus"
)

func TestCollector(t *testing.T) {
m, err := NewMetrics()
check(t, "Failed to create metrics", err)
reg := prometheus.NewRegistry()
check(t, "Failed to register metrics", reg.Register(m))
fams, err := reg.Gather()
check(t, "Failed to gather metrics", err)
names := []string{
updateErrorName,
verifyErrorName,
expirationName,
}
if want, got := len(names), len(fams); want != got {
t.Fatalf("Expected %v metrics; got: %d", want, got)
}
for i, want := range names {
if got := *fams[i].Name; want != got {
t.Fatalf("Unexpected metric name; want: %v; got: %v", want, got)
}
}
}

func TestMetricNames(t *testing.T) {
tests := []struct {
desc string
Expand Down Expand Up @@ -52,6 +74,12 @@ func TestMetricNames(t *testing.T) {
namespace: "foo",
subsystem: "bar",
},
{
desc: "foo_server",
options: []Option{WithNamespace("foo"), WithServer()},
namespace: "foo",
subsystem: "server",
},
}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
Expand Down Expand Up @@ -251,7 +279,7 @@ func TestExpiration(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
m, err := NewMetrics()
m, err := NewMetrics(WithErrorLogger(t))
check(t, "Failed to create metrics", err)
m.Update(tt.config, nil)
got := readGauge(t, m.expiration)
Expand Down

0 comments on commit 6115b1a

Please sign in to comment.