Skip to content

Commit

Permalink
adds tests
Browse files Browse the repository at this point in the history
Signed-off-by: mattb18 <[email protected]>
  • Loading branch information
mattb18 committed Dec 31, 2024
1 parent fdfb645 commit 9cf69fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
31 changes: 31 additions & 0 deletions prober/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,34 @@ func TestGRPCHealthCheckUnimplemented(t *testing.T) {

checkRegistryResults(expectedResults, mfs, t)
}

func TestGRPCAbsentFailedTLS(t *testing.T) {
testCTX, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
registry := prometheus.NewRegistry()

// probe and invalid port to trigger TCP/TLS error
result := ProbeGRPC(testCTX, "localhost:0",
config.Module{Timeout: time.Second, GRPC: config.GRPCProbe{
IPProtocolFallback: false,
Service: "NonExistingService",
},
}, registry, promslog.NewNopLogger())

if result {
t.Fatalf("GRPC probe succeeded, should have failed")
}

mfs, err := registry.Gather()
if err != nil {
t.Fatal(err)
}

absentMetrics := []string{
"probe_ssl_earliest_cert_expiry",
"probe_tls_version_info",
"probe_ssl_last_chain_info",
}

checkAbsentMetrics(absentMetrics, mfs, t)
}
10 changes: 10 additions & 0 deletions prober/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"math/big"
"net"
"slices"
"testing"
"time"

Expand Down Expand Up @@ -249,3 +250,12 @@ func checkMetrics(expected map[string]map[string]map[string]struct{}, mfs []*dto
}
}
}

func checkAbsentMetrics(absent []string, mfs []*dto.MetricFamily, t *testing.T) {
for _, v := range mfs {
name := v.GetName()
if slices.Contains(absent, name) {
t.Fatalf("metric %s was found but should be absent", name)
}
}
}

0 comments on commit 9cf69fb

Please sign in to comment.