prober: remove duplicated tests (#324)
authorSimon Pasquier <spasquie@redhat.com>
Mon, 2 Sep 2019 15:44:43 +0000 (17:44 +0200)
committerBrian Brazil <brian.brazil@robustperception.io>
Mon, 2 Sep 2019 15:44:43 +0000 (16:44 +0100)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
prober/dns_test.go
prober/tcp_test.go

index a4634839bdcb5686f69332777da3a239e0b14a0b..767a31c781bfa9cefc3f34d0a23b4589d88f4bb1 100644 (file)
@@ -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)
index 9bcc714a1b8344b81f5da511c4f2e0c816972e07..82013003ab5dee2f6ee61965b9d2344d392f5365 100644 (file)
@@ -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) {