Skip to content

Commit

Permalink
prober: remove duplicated tests (#324)
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Pasquier <[email protected]>
  • Loading branch information
simonpasquier authored and brian-brazil committed Sep 2, 2019
1 parent ef3fdc3 commit ce8e995
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 115 deletions.
57 changes: 3 additions & 54 deletions prober/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,78 +407,27 @@ func TestDNSProtocol(t *testing.T) {

_, port, _ := net.SplitHostPort(addr.String())

// Force IPv4
// Prefer IPv6
module := config.Module{
Timeout: time.Second,
DNS: config.DNSProbe{
QueryName: "example.com",
TransportProtocol: protocol,
IPProtocol: "ip4",
IPProtocol: "ip6",
},
}
registry := prometheus.NewRegistry()
testCTX, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result := ProbeDNS(testCTX, net.JoinHostPort("localhost", port), module, registry, log.NewNopLogger())
if !result {
t.Fatalf("DNS protocol: \"%v4\" connection test failed, expected success.", protocol)
t.Fatalf("DNS protocol: \"%v\", preferred \"ip6\" connection test failed, expected success.", protocol)
}
mfs, err := registry.Gather()
if err != nil {
t.Fatal(err)
}

expectedResults := map[string]float64{
"probe_ip_protocol": 4,
}
checkRegistryResults(expectedResults, mfs, t)

// Force IPv6
module = config.Module{
Timeout: time.Second,
DNS: config.DNSProbe{
QueryName: "example.com",
TransportProtocol: protocol,
IPProtocol: "ip6",
},
}
registry = prometheus.NewRegistry()
testCTX, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result = ProbeDNS(testCTX, net.JoinHostPort("localhost", port), module, registry, log.NewNopLogger())
if !result {
t.Fatalf("DNS protocol: \"%v6\" connection test failed, expected success.", protocol)
}
mfs, err = registry.Gather()
if err != nil {
t.Fatal(err)
}
expectedResults = map[string]float64{
"probe_ip_protocol": 6,
}
checkRegistryResults(expectedResults, mfs, t)

// Prefer IPv6
module = config.Module{
Timeout: time.Second,
DNS: config.DNSProbe{
QueryName: "example.com",
TransportProtocol: protocol,
IPProtocol: "ip6",
},
}
registry = prometheus.NewRegistry()
testCTX, cancel = context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result = ProbeDNS(testCTX, net.JoinHostPort("localhost", port), module, registry, log.NewNopLogger())
if !result {
t.Fatalf("DNS protocol: \"%v\", preferred \"ip6\" connection test failed, expected success.", protocol)
}
mfs, err = registry.Gather()
if err != nil {
t.Fatal(err)
}
expectedResults = map[string]float64{
"probe_ip_protocol": 6,
}
checkRegistryResults(expectedResults, mfs, t)
Expand Down
63 changes: 2 additions & 61 deletions prober/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ func TestTCPConnectionProtocol(t *testing.T) {

_, port, _ := net.SplitHostPort(ln.Addr().String())

// Force IPv4
// Prefer IPv4
module := config.Module{
TCP: config.TCPProbe{
IPProtocol: "ip4",
Expand All @@ -447,7 +447,7 @@ func TestTCPConnectionProtocol(t *testing.T) {
registry := prometheus.NewRegistry()
result := ProbeTCP(testCTX, net.JoinHostPort("localhost", port), module, registry, log.NewNopLogger())
if !result {
t.Fatalf("TCP protocol: \"tcp4\" connection test failed, expected success.")
t.Fatalf("TCP protocol: \"tcp\", prefer: \"ip4\" connection test failed, expected success.")
}
mfs, err := registry.Gather()
if err != nil {
Expand All @@ -458,46 +458,6 @@ func TestTCPConnectionProtocol(t *testing.T) {
}
checkRegistryResults(expectedResults, mfs, t)

// Force IPv6
module = config.Module{
TCP: config.TCPProbe{},
}

registry = prometheus.NewRegistry()
result = ProbeTCP(testCTX, net.JoinHostPort("localhost", port), module, registry, log.NewNopLogger())
if !result {
t.Fatalf("TCP protocol: \"tcp6\" connection test failed, expected success.")
}
mfs, err = registry.Gather()
if err != nil {
t.Fatal(err)
}
expectedResults = map[string]float64{
"probe_ip_protocol": 6,
}
checkRegistryResults(expectedResults, mfs, t)

// Prefer IPv4
module = config.Module{
TCP: config.TCPProbe{
IPProtocol: "ip4",
},
}

registry = prometheus.NewRegistry()
result = ProbeTCP(testCTX, net.JoinHostPort("localhost", port), module, registry, log.NewNopLogger())
if !result {
t.Fatalf("TCP protocol: \"tcp\", prefer: \"ip4\" connection test failed, expected success.")
}
mfs, err = registry.Gather()
if err != nil {
t.Fatal(err)
}
expectedResults = map[string]float64{
"probe_ip_protocol": 4,
}
checkRegistryResults(expectedResults, mfs, t)

// Prefer IPv6
module = config.Module{
TCP: config.TCPProbe{
Expand Down Expand Up @@ -537,25 +497,6 @@ func TestTCPConnectionProtocol(t *testing.T) {
"probe_ip_protocol": 6,
}
checkRegistryResults(expectedResults, mfs, t)

// No protocol
module = config.Module{
TCP: config.TCPProbe{},
}

registry = prometheus.NewRegistry()
result = ProbeTCP(testCTX, net.JoinHostPort("localhost", port), module, registry, log.NewNopLogger())
if !result {
t.Fatalf("TCP connection test with protocol unspecified failed, expected success.")
}
mfs, err = registry.Gather()
if err != nil {
t.Fatal(err)
}
expectedResults = map[string]float64{
"probe_ip_protocol": 6,
}
checkRegistryResults(expectedResults, mfs, t)
}

func TestPrometheusTimeoutTCP(t *testing.T) {
Expand Down

0 comments on commit ce8e995

Please sign in to comment.