From: Simon Pasquier Date: Mon, 2 Sep 2019 15:44:43 +0000 (+0200) Subject: prober: remove duplicated tests (#324) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ce8e9952a074768995cb67de0bc31bb43c1ec7c1;p=blackbox_exporter.git prober: remove duplicated tests (#324) Signed-off-by: Simon Pasquier --- diff --git a/prober/dns_test.go b/prober/dns_test.go index a463483..767a31c 100644 --- a/prober/dns_test.go +++ b/prober/dns_test.go @@ -407,13 +407,13 @@ 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() @@ -421,64 +421,13 @@ func TestDNSProtocol(t *testing.T) { 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) diff --git a/prober/tcp_test.go b/prober/tcp_test.go index 9bcc714..8201300 100644 --- a/prober/tcp_test.go +++ b/prober/tcp_test.go @@ -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", @@ -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 { @@ -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{ @@ -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) {