nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: favonia/cloudflare-ddns
Pull request #46 (2021-08-01 21:20:22)

test(ipnet): 100% coverage of ipnet


Patch:
diff --git a/internal/ipnet/ipnet.go b/internal/ipnet/ipnet.go
index db7c867..e655e77 100644
--- a/internal/ipnet/ipnet.go
+++ b/internal/ipnet/ipnet.go
@@ -1,20 +1,31 @@
+// Package ipnet contains utility functions for IP network versions
 package ipnet
 
 import (
 	"fmt"
 )
 
+// Type is the type of IP networks.
 type Type int
 
 const (
+	// IP4 is IP version 4.
 	IP4 Type = 4
+	// IP6 is IP version 6.
 	IP6 Type = 6
 )
 
+// String returns a description of the IP network.
 func (t Type) String() string {
-	return fmt.Sprintf("IPv%d", t)
+	switch t {
+	case IP4, IP6:
+		return fmt.Sprintf("IPv%d", t)
+	default:
+		return "(unrecognized IP network)"
+	}
 }
 
+// RecordType prints out the type of DNS records for the IP network.
 func (t Type) RecordType() string {
 	switch t {
 	case IP4:
@@ -26,6 +37,12 @@ func (t Type) RecordType() string {
 	}
 }
 
+// Int returns the version of the IP networks. It is either 4 or 6.
 func (t Type) Int() int {
-	return int(t)
+	switch t {
+	case IP4, IP6:
+		return int(t)
+	default:
+		return 0
+	}
 }


Test patch:
diff --git a/internal/ipnet/ipnet_test.go b/internal/ipnet/ipnet_test.go
new file mode 100644
index 0000000..6c2b9fb
--- /dev/null
+++ b/internal/ipnet/ipnet_test.go
@@ -0,0 +1,54 @@
+package ipnet_test
+
+import (
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+
+	"github.com/favonia/cloudflare-ddns-go/internal/ipnet"
+)
+
+func TestString(t *testing.T) {
+	t.Parallel()
+
+	for _, c := range [...]struct {
+		input  ipnet.Type
+		output string
+	}{
+		{ipnet.IP4, "IPv4"},
+		{ipnet.IP6, "IPv6"},
+		{ipnet.Type(100), "(unrecognized IP network)"},
+	} {
+		assert.Equal(t, c.output, c.input.String())
+	}
+}
+
+func TestRecordType(t *testing.T) {
+	t.Parallel()
+
+	for _, c := range [...]struct {
+		input  ipnet.Type
+		output string
+	}{
+		{ipnet.IP4, "A"},
+		{ipnet.IP6, "AAAA"},
+		{ipnet.Type(100), ""},
+	} {
+		assert.Equal(t, c.output, c.input.RecordType())
+	}
+}
+
+func TestInt(t *testing.T) {
+	t.Parallel()
+
+	for _, c := range [...]struct {
+		input  ipnet.Type
+		output int
+	}{
+		{ipnet.IP4, 4},
+		{ipnet.IP6, 6},
+		{ipnet.Type(100), 0},
+	} {
+		assert.Equal(t, c.output, c.input.Int())
+	}
+}
Repository: favonia/cloudflare-ddns
Pull request #859 (2024-08-10 08:55:08)

fix(updater): show the hint to disable a network when IP detection timeouts


Patch:
diff --git a/internal/updater/updater.go b/internal/updater/updater.go
index 9b69994..475f592 100644
--- a/internal/updater/updater.go
+++ b/internal/updater/updater.go
@@ -57,13 +57,7 @@ func detectIP(ctx context.Context, ppfmt pp.PP,
 	} else {
 		ppfmt.Warningf(pp.EmojiError, "Failed to detect the %s address", ipNet.Describe())
 
-		if ShouldDisplayHints[HintDetectionTimeouts] && errors.Is(context.Cause(ctx), errTimeout) {
-			ppfmt.Infof(pp.EmojiHint,
-				"If your network is experiencing high latency, consider increasing DETECTION_TIMEOUT=%v",
-				c.DetectionTimeout,
-			)
-			ShouldDisplayHints[HintDetectionTimeouts] = false
-		} else if ShouldDisplayHints[getHintIDForDetection(ipNet)] {
+		if ShouldDisplayHints[getHintIDForDetection(ipNet)] {
 			switch ipNet {
 			case ipnet.IP6:
 				ppfmt.Infof(pp.EmojiHint, "If you are using Docker or Kubernetes, IPv6 often requires additional setups")     //nolint:lll
@@ -73,6 +67,12 @@ func detectIP(ctx context.Context, ppfmt pp.PP,
 				ppfmt.Infof(pp.EmojiHint, "If your network does not support IPv4, you can disable it with IP4_PROVIDER=none") //nolint:lll
 			}
 		}
+		if ShouldDisplayHints[HintDetectionTimeouts] && errors.Is(context.Cause(ctx), errTimeout) {
+			ppfmt.Infof(pp.EmojiHint,
+				"If your network is experiencing high latency, consider increasing DETECTION_TIMEOUT=%v",
+				c.DetectionTimeout,
+			)
+		}
 	}
 	ShouldDisplayHints[getHintIDForDetection(ipNet)] = false
 	return ip, generateDetectMessage(ipNet, ok)


Test patch:
diff --git a/internal/updater/updater_test.go b/internal/updater/updater_test.go
index a593baa..e6ac33c 100644
--- a/internal/updater/updater_test.go
+++ b/internal/updater/updater_test.go
@@ -556,6 +556,7 @@ func TestUpdateIPs(t *testing.T) {
 							},
 						),
 					p.EXPECT().Warningf(pp.EmojiError, "Failed to detect the %s address", "IPv4"),
+					p.EXPECT().Infof(pp.EmojiHint, "If your network does not support IPv4, you can disable it with IP4_PROVIDER=none"),                    //nolint:lll
 					p.EXPECT().Infof(pp.EmojiHint, "If your network is experiencing high latency, consider increasing DETECTION_TIMEOUT=%v", time.Second), //nolint:lll
 				)
 			},