Repository: favonia/cloudflare-ddns
Pull request #940 (2024-09-22 02:48:36)

fix(provider): fix the name and messages of custom URL providers

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/940?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 95.78%. Comparing base [(`3e80358`)](https://app.codecov.io/gh/favonia/cloudflare-ddns/commit/3e803584db697ff9d89581f5e79df79465dc6521?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) to head [(`134dc4d`)](https://app.codecov.io/gh/favonia/cloudflare-ddns/commit/134dc4dace9347f88050ad8a3371d25d27a8ae2a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia).

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main     #940   +/-   ##
=======================================
  Coverage   95.78%   95.78%           
=======================================
  Files          60       60           
  Lines        2704     2704           
=======================================
  Hits         2590     2590           
  Misses        104      104           
  Partials       10       10           
```

| [Flag](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/940/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) | Coverage Δ | |
|---|---|---|
| [unittests](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/940/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) | `95.78% <100.00%> (ø)` | |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia#carryforward-flags-in-the-pull-request-comment) to find out more.

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/940?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia).


Patch:
diff --git a/internal/config/env_provider.go b/internal/config/env_provider.go
index a273607..4d433d6 100644
--- a/internal/config/env_provider.go
+++ b/internal/config/env_provider.go
@@ -115,7 +115,7 @@ func ReadProvider(ppfmt pp.PP, key, keyDeprecated string, field *provider.Provid
 
 	if strings.HasPrefix(val, "url:") {
 		url := strings.TrimSpace(strings.TrimPrefix(val, "url:"))
-		p, ok := provider.NewCustom(ppfmt, url)
+		p, ok := provider.NewCustomURL(ppfmt, url)
 		if ok {
 			*field = p
 		}
diff --git a/internal/provider/custom.go b/internal/provider/custom.go
index bfd231c..f8ff80f 100644
--- a/internal/provider/custom.go
+++ b/internal/provider/custom.go
@@ -9,33 +9,33 @@ import (
 	"github.com/favonia/cloudflare-ddns/internal/provider/protocol"
 )
 
-// NewCustom creates a HTTP provider.
-func NewCustom(ppfmt pp.PP, rawURL string) (Provider, bool) {
+// NewCustomURL creates a HTTP provider.
+func NewCustomURL(ppfmt pp.PP, rawURL string) (Provider, bool) {
 	u, err := url.Parse(rawURL)
 	if err != nil {
-		ppfmt.Noticef(pp.EmojiUserError, "Failed to parse the custom provider (redacted)")
+		ppfmt.Noticef(pp.EmojiUserError, `Failed to parse the provider url:(redacted)`)
 		return nil, false
 	}
 
 	if !u.IsAbs() || u.Opaque != "" || u.Host == "" {
-		ppfmt.Noticef(pp.EmojiUserError, `The custom provider (redacted) does not look like a valid URL`)
+		ppfmt.Noticef(pp.EmojiUserError, `The provider url:(redacted) does not contain a valid URL`)
 		return nil, false
 	}
 
 	switch u.Scheme {
 	case "http":
-		ppfmt.Noticef(pp.EmojiUserWarning, "The custom provider (redacted) uses HTTP; consider using HTTPS instead")
+		ppfmt.Noticef(pp.EmojiUserWarning, "The provider url:(redacted) uses HTTP; consider using HTTPS instead")
 
 	case "https":
 		// HTTPS is good!
 
 	default:
-		ppfmt.Noticef(pp.EmojiUserError, `The custom provider (redacted) must use HTTP or HTTPS`)
+		ppfmt.Noticef(pp.EmojiUserError, `The provider url:(redacted) only supports HTTP and HTTPS`)
 		return nil, false
 	}
 
 	return NewHappyEyeballs(protocol.HTTP{
-		ProviderName: "custom",
+		ProviderName: "url:(redacted)",
 		URL: map[ipnet.Type]protocol.Switch{
 			ipnet.IP4: protocol.Constant(rawURL),
 			ipnet.IP6: protocol.Constant(rawURL),
@@ -43,10 +43,10 @@ func NewCustom(ppfmt pp.PP, rawURL string) (Provider, bool) {
 	}), true
 }
 
-// MustNewCustom creates a HTTP provider and panics if it fails.
-func MustNewCustom(rawURL string) Provider {
+// MustNewCustomURL creates a HTTP provider and panics if it fails.
+func MustNewCustomURL(rawURL string) Provider {
 	var buf strings.Builder
-	p, ok := NewCustom(pp.NewDefault(&buf), rawURL)
+	p, ok := NewCustomURL(pp.NewDefault(&buf), rawURL)
 	if !ok {
 		panic(buf.String())
 	}


Test patch:
diff --git a/internal/config/env_provider_test.go b/internal/config/env_provider_test.go
index e2feb7a..aba62f4 100644
--- a/internal/config/env_provider_test.go
+++ b/internal/config/env_provider_test.go
@@ -24,7 +24,7 @@ func TestReadProvider(t *testing.T) {
 		trace  = provider.NewCloudflareTrace()
 		local  = provider.NewLocal()
 		ipify  = provider.NewIpify()
-		custom = provider.MustNewCustom("https://url.io")
+		custom = provider.MustNewCustomURL("https://url.io")
 	)
 
 	for name, tc := range map[string]struct {
diff --git a/internal/provider/custom_test.go b/internal/provider/custom_test.go
index 5713dac..caaca60 100644
--- a/internal/provider/custom_test.go
+++ b/internal/provider/custom_test.go
@@ -11,10 +11,10 @@ import (
 	"github.com/favonia/cloudflare-ddns/internal/provider"
 )
 
-func TestCustomName(t *testing.T) {
+func TestCustomURLName(t *testing.T) {
 	t.Parallel()
 
-	require.Equal(t, "custom", provider.Name(provider.MustNewCustom("https://1.1.1.1/")))
+	require.Equal(t, "url:(redacted)", provider.Name(provider.MustNewCustomURL("https://1.1.1.1/")))
 }
 
 func TestNewCustom(t *testing.T) {
@@ -29,25 +29,25 @@ func TestNewCustom(t *testing.T) {
 		{
 			":::::", false,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiUserError, "Failed to parse the custom provider (redacted)")
+				m.EXPECT().Noticef(pp.EmojiUserError, "Failed to parse the provider url:(redacted)")
 			},
 		},
 		{
 			"http://1.2.3.4", true,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiUserWarning, "The custom provider (redacted) uses HTTP; consider using HTTPS instead")
+				m.EXPECT().Noticef(pp.EmojiUserWarning, "The provider url:(redacted) uses HTTP; consider using HTTPS instead")
 			},
 		},
 		{
 			"ftp://1.2.3.4", false,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiUserError, `The custom provider (redacted) must use HTTP or HTTPS`)
+				m.EXPECT().Noticef(pp.EmojiUserError, `The provider url:(redacted) only supports HTTP and HTTPS`)
 			},
 		},
 		{
 			"", false,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Noticef(pp.EmojiUserError, `The custom provider (redacted) does not look like a valid URL`)
+				m.EXPECT().Noticef(pp.EmojiUserError, `The provider url:(redacted) does not contain a valid URL`)
 			},
 		},
 	} {
@@ -59,7 +59,7 @@ func TestNewCustom(t *testing.T) {
 			if tc.prepareMockPP != nil {
 				tc.prepareMockPP(mockPP)
 			}
-			p, ok := provider.NewCustom(mockPP, tc.input)
+			p, ok := provider.NewCustomURL(mockPP, tc.input)
 			require.Equal(t, tc.ok, ok)
 			if ok {
 				require.NotNil(t, p)
@@ -87,9 +87,9 @@ func TestMustNewCustom(t *testing.T) {
 			t.Parallel()
 
 			if tc.ok {
-				require.NotPanics(t, func() { provider.MustNewCustom(tc.input) })
+				require.NotPanics(t, func() { provider.MustNewCustomURL(tc.input) })
 			} else {
-				require.Panics(t, func() { provider.MustNewCustom(tc.input) })
+				require.Panics(t, func() { provider.MustNewCustomURL(tc.input) })
 			}
 		})
 	}