Repository: favonia/cloudflare-ddns
Pull request #999 (2024-12-14 14:37:33)

test(config): test the provider `cloudflare.trace:URL`

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/999?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 94.94%. Comparing base [(`3b0cdeb`)](https://app.codecov.io/gh/favonia/cloudflare-ddns/commit/3b0cdebf346e532a15fc4c8c2d5033d803821d39?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) to head [(`ece10e1`)](https://app.codecov.io/gh/favonia/cloudflare-ddns/commit/ece10e1c84e296ff87ace3f4b396ed91c0d66a88?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     #999      +/-   ##
==========================================
+ Coverage   94.58%   94.94%   +0.35%     
==========================================
  Files          62       62              
  Lines        3364     3364              
==========================================
+ Hits         3182     3194      +12     
+ Misses        170      158      -12     
  Partials       12       12              
```

| [Flag](https://app.codecov.io/gh/favonia/cloudflare-ddns/pull/999/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/999/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=favonia) | `94.94% <100.00%> (+0.35%)` | :arrow_up: |

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/999?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 59142ec..d0b15aa 100644
--- a/internal/config/env_provider.go
+++ b/internal/config/env_provider.go
@@ -100,7 +100,8 @@ func ReadProvider(ppfmt pp.PP, key, keyDeprecated string, field *provider.Provid
 		*field = provider.NewCloudflareTrace()
 		return true
 	case len(parts) == 2 && parts[0] == "cloudflare.trace":
-		ppfmt.Hintf(pp.HintDebugConstProvider, `You are using the undocumented "cloudflare.trace:..." provider`)
+		ppfmt.Hintf(pp.HintUndocumentedCustomCloudflareTraceProvider,
+			`You are using the undocumented "cloudflare.trace" provider with custom URL`)
 		if parts[1] == "" {
 			ppfmt.Noticef(
 				pp.EmojiUserError,
@@ -148,7 +149,8 @@ func ReadProvider(ppfmt pp.PP, key, keyDeprecated string, field *provider.Provid
 		*field = nil
 		return true
 	case len(parts) == 2 && parts[0] == "debug.const":
-		ppfmt.Hintf(pp.HintDebugConstProvider, `You are using the undocumented "debug.const" provider`)
+		ppfmt.Hintf(pp.HintUndocumentedDebugConstProvider,
+			`You are using the undocumented "debug.const" provider`)
 		if parts[1] == "" {
 			ppfmt.Noticef(
 				pp.EmojiUserError,
diff --git a/internal/pp/hint.go b/internal/pp/hint.go
index 60a26ad..aab0610 100644
--- a/internal/pp/hint.go
+++ b/internal/pp/hint.go
@@ -5,19 +5,20 @@ type Hint int
 
 // All the registered hints.
 const (
-	HintUpdateDockerTemplate           Hint = iota // PUID or PGID was used
-	HintAuthTokenNewPrefix                         // "CF_*" to "CLOUDFLARE_*"
-	HintIP4DetectionFails                          // How to turn off IPv4
-	HintIP6DetectionFails                          // How to set up IPv6 or turn it off
-	HintIP4MappedIP6Address                        // IPv4-mapped IPv6 addresses are bad for AAAA records
-	HintDetectionTimeouts                          // Longer detection timeout
-	HintUpdateTimeouts                             // Longer update timeout
-	HintRecordPermission                           // Permissions to update DNS tokens
-	HintWAFListPermission                          // Permissions to update WAF lists
-	HintMismatchedRecordAttributes                 // Attributes of DNS records have been changed
-	HintMismatchedWAFListAttributes                // Attributes of WAF lists have been changed
-	HintExperimentalShoutrrr                       // New feature introduced in 1.12.0 on 2024/6/28
-	HintExperimentalWAF                            // New feature introduced in 1.14.0 on 2024/8/25
-	HintExperimentalLocalWithInterface             // New feature introduced in 1.15.0
-	HintDebugConstProvider                         // Undocumented feature
+	HintUpdateDockerTemplate                      Hint = iota // PUID or PGID was used
+	HintAuthTokenNewPrefix                                    // "CF_*" to "CLOUDFLARE_*"
+	HintIP4DetectionFails                                     // How to turn off IPv4
+	HintIP6DetectionFails                                     // How to set up IPv6 or turn it off
+	HintIP4MappedIP6Address                                   // IPv4-mapped IPv6 addresses are bad for AAAA records
+	HintDetectionTimeouts                                     // Longer detection timeout
+	HintUpdateTimeouts                                        // Longer update timeout
+	HintRecordPermission                                      // Permissions to update DNS tokens
+	HintWAFListPermission                                     // Permissions to update WAF lists
+	HintMismatchedRecordAttributes                            // Attributes of DNS records have been changed
+	HintMismatchedWAFListAttributes                           // Attributes of WAF lists have been changed
+	HintExperimentalShoutrrr                                  // New feature introduced in 1.12.0 on 2024/6/28
+	HintExperimentalWAF                                       // New feature introduced in 1.14.0 on 2024/8/25
+	HintExperimentalLocalWithInterface                        // New feature introduced in 1.15.0
+	HintUndocumentedDebugConstProvider                        // Undocumented feature
+	HintUndocumentedCustomCloudflareTraceProvider             // Undocumented feature
 )


Test patch:
diff --git a/internal/config/env_provider_test.go b/internal/config/env_provider_test.go
index c30928e..affa2ea 100644
--- a/internal/config/env_provider_test.go
+++ b/internal/config/env_provider_test.go
@@ -23,6 +23,7 @@ func TestReadProvider(t *testing.T) {
 		none          provider.Provider
 		doh           = provider.NewCloudflareDOH()
 		trace         = provider.NewCloudflareTrace()
+		traceCustom   = provider.NewCloudflareTraceCustom("https://1.1.1.1/cdn-cgi/trace")
 		local         = provider.NewLocal()
 		localLoopback = provider.NewLocalWithInterface("lo")
 		ipify         = provider.NewIpify()
@@ -113,9 +114,24 @@ func TestReadProvider(t *testing.T) {
 			},
 		},
 		"cloudflare.trace": {true, " cloudflare.trace", false, "", none, trace, true, nil},
-		"cloudflare.doh":   {true, "    \tcloudflare.doh   ", false, "", none, doh, true, nil},
-		"none":             {true, "   none   ", false, "", trace, none, true, nil},
-		"local":            {true, "   local   ", false, "", trace, local, true, nil},
+		"cloudflare.trace:https://1.1.1.1/cdn-cgi/trace": {
+			true, "   cloudflare.trace:https://1.1.1.1/cdn-cgi/trace ", false, "", trace, traceCustom, true,
+			func(m *mocks.MockPP) {
+				m.EXPECT().Hintf(pp.HintUndocumentedCustomCloudflareTraceProvider, `You are using the undocumented "cloudflare.trace" provider with custom URL`)
+			},
+		},
+		"cloudflare.trace:": {
+			true, "   cloudflare.trace: ", false, "", trace, trace, false,
+			func(m *mocks.MockPP) {
+				gomock.InOrder(
+					m.EXPECT().Hintf(pp.HintUndocumentedCustomCloudflareTraceProvider, `You are using the undocumented "cloudflare.trace" provider with custom URL`),
+					m.EXPECT().Noticef(pp.EmojiUserError, `%s=cloudflare.trace: must be followed by a URL`, key),
+				)
+			},
+		},
+		"cloudflare.doh": {true, "    \tcloudflare.doh   ", false, "", none, doh, true, nil},
+		"none":           {true, "   none   ", false, "", trace, none, true, nil},
+		"local":          {true, "   local   ", false, "", trace, local, true, nil},
 		"local.iface:lo": {
 			true, "   local.iface   :  lo ", false, "", trace, localLoopback, true,
 			func(m *mocks.MockPP) {
@@ -144,14 +160,14 @@ func TestReadProvider(t *testing.T) {
 		"debug.const:1.1.1.1": {
 			true, "   debug.const   :  1.1.1.1 ", false, "", trace, debugConst, true,
 			func(m *mocks.MockPP) {
-				m.EXPECT().Hintf(pp.HintDebugConstProvider, `You are using the undocumented "debug.const" provider`)
+				m.EXPECT().Hintf(pp.HintUndocumentedDebugConstProvider, `You are using the undocumented "debug.const" provider`)
 			},
 		},
 		"debug.const": {
 			true, "   debug.const: ", false, "", trace, trace, false,
 			func(m *mocks.MockPP) {
 				gomock.InOrder(
-					m.EXPECT().Hintf(pp.HintDebugConstProvider, `You are using the undocumented "debug.const" provider`),
+					m.EXPECT().Hintf(pp.HintUndocumentedDebugConstProvider, `You are using the undocumented "debug.const" provider`),
 					m.EXPECT().Noticef(pp.EmojiUserError, `%s=debug.const: must be followed by an IP address`, key),
 				)
 			},