Repository: apigee/registry
Pull request #1146 (2023-04-13 17:56:44)

fix differences from rules audit
These were issues I found in the rules when I was documenting all the rules in the wiki. https://github.com/apigee/registry/wiki/registry-check-and-rules

codecov[bot]: ## [Codecov](https://codecov.io/gh/apigee/registry/pull/1146?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee) Report
> Merging [#1146](https://codecov.io/gh/apigee/registry/pull/1146?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee) (0245d48) into [main](https://codecov.io/gh/apigee/registry/commit/e9340dae7b33ffe020a3cee0062ae1dc01691a84?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee) (e9340da) will **decrease** coverage by `0.01%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##             main    #1146      +/-   ##
==========================================
- Coverage   70.87%   70.86%   -0.01%     
==========================================
  Files         146      146              
  Lines       11977    11973       -4     
==========================================
- Hits         8489     8485       -4     
  Misses       2772     2772              
  Partials      716      716              
```


| [Impacted Files](https://codecov.io/gh/apigee/registry/pull/1146?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee) | Coverage Δ | |
|---|---|---|
| [cmd/registry/cmd/check/rules/rule105/rule105.go](https://codecov.io/gh/apigee/registry/pull/1146?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee#diff-Y21kL3JlZ2lzdHJ5L2NtZC9jaGVjay9ydWxlcy9ydWxlMTA1L3J1bGUxMDUuZ28=) | `100.00% <100.00%> (ø)` | |
| [cmd/registry/cmd/check/rules/rule109/rule109.go](https://codecov.io/gh/apigee/registry/pull/1146?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee#diff-Y21kL3JlZ2lzdHJ5L2NtZC9jaGVjay9ydWxlcy9ydWxlMTA5L3J1bGUxMDkuZ28=) | `100.00% <100.00%> (ø)` | |
| [cmd/registry/cmd/check/rules/rule112/rule112.go](https://codecov.io/gh/apigee/registry/pull/1146?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee#diff-Y21kL3JlZ2lzdHJ5L2NtZC9jaGVjay9ydWxlcy9ydWxlMTEyL3J1bGUxMTIuZ28=) | `100.00% <100.00%> (ø)` | |
| [cmd/registry/cmd/check/rules/rule113/rule113.go](https://codecov.io/gh/apigee/registry/pull/1146?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee#diff-Y21kL3JlZ2lzdHJ5L2NtZC9jaGVjay9ydWxlcy9ydWxlMTEzL3J1bGUxMTMuZ28=) | `100.00% <100.00%> (ø)` | |

... and [2 files with indirect coverage changes](https://codecov.io/gh/apigee/registry/pull/1146/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee)

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apigee)


Patch:
diff --git a/cmd/registry/cmd/check/rules/rule105/rule105.go b/cmd/registry/cmd/check/rules/rule105/rule105.go
index 91569a1..1ba8a9c 100644
--- a/cmd/registry/cmd/check/rules/rule105/rule105.go
+++ b/cmd/registry/cmd/check/rules/rule105/rule105.go
@@ -16,9 +16,9 @@ package rule105
 
 import (
 	"context"
-	"net/url"
 
 	"github.com/apigee/registry/cmd/registry/cmd/check/lint"
+	"github.com/apigee/registry/cmd/registry/cmd/check/rules/util"
 	"github.com/apigee/registry/pkg/application/check"
 	"github.com/apigee/registry/rpc"
 )
@@ -41,14 +41,6 @@ var sourceUriFormat = &lint.ApiSpecRule{
 		return a.SourceUri != ""
 	},
 	ApplyToApiSpec: func(ctx context.Context, a *rpc.ApiSpec) []*check.Problem {
-		u, err := url.ParseRequestURI(a.SourceUri)
-		if err != nil || u.Host == "" {
-			return []*check.Problem{{
-				Severity:   check.Problem_ERROR,
-				Message:    `source_uri must be an absolute URI.`,
-				Suggestion: `Ensure source_uri includes a host.`,
-			}}
-		}
-		return nil
+		return util.CheckURI("source_uri", a.SourceUri)
 	},
 }
diff --git a/cmd/registry/cmd/check/rules/rule109/rule109.go b/cmd/registry/cmd/check/rules/rule109/rule109.go
index 1623dda..ec6ff35 100644
--- a/cmd/registry/cmd/check/rules/rule109/rule109.go
+++ b/cmd/registry/cmd/check/rules/rule109/rule109.go
@@ -42,6 +42,6 @@ var displayName = &lint.FieldRule{
 		return field == fieldName
 	},
 	ApplyToField: func(ctx context.Context, resource lint.Resource, field string, value interface{}) []*check.Problem {
-		return util.CheckUTF(fieldName, value, 65)
+		return util.CheckUTF(fieldName, value, 64)
 	},
 }
diff --git a/cmd/registry/cmd/check/rules/rule112/rule112.go b/cmd/registry/cmd/check/rules/rule112/rule112.go
index 95dda6f..e6e46da 100644
--- a/cmd/registry/cmd/check/rules/rule112/rule112.go
+++ b/cmd/registry/cmd/check/rules/rule112/rule112.go
@@ -88,10 +88,10 @@ func checkLabel(k string, v string) []*check.Problem {
 			Suggestion: `Fix key.`,
 		})
 	}
-	if count := utf8.RuneCountInString(k); count > 64 {
+	if count := utf8.RuneCountInString(k); count > 63 {
 		probs = append(probs, &check.Problem{
 			Severity:   check.Problem_ERROR,
-			Message:    fmt.Sprintf(`Key %q exceeds max length of 64 characters.`, k),
+			Message:    fmt.Sprintf(`Key %q exceeds max length of 63 characters.`, k),
 			Suggestion: `Fix key.`,
 		})
 	}
@@ -102,10 +102,10 @@ func checkLabel(k string, v string) []*check.Problem {
 			Suggestion: `Fix value.`,
 		})
 	}
-	if count := utf8.RuneCountInString(v); count > 64 {
+	if count := utf8.RuneCountInString(v); count > 63 {
 		probs = append(probs, &check.Problem{
 			Severity:   check.Problem_ERROR,
-			Message:    fmt.Sprintf(`Value for key %q exceeds max length of 64 characters.`, k),
+			Message:    fmt.Sprintf(`Value for key %q exceeds max length of 63 characters.`, k),
 			Suggestion: `Fix value.`,
 		})
 	}
diff --git a/cmd/registry/cmd/check/rules/rule113/rule113.go b/cmd/registry/cmd/check/rules/rule113/rule113.go
index 697635b..cfd864d 100644
--- a/cmd/registry/cmd/check/rules/rule113/rule113.go
+++ b/cmd/registry/cmd/check/rules/rule113/rule113.go
@@ -93,10 +93,10 @@ func checkAnnotation(k string, v string) []*check.Problem {
 			Suggestion: `Fix key.`,
 		})
 	}
-	if count := utf8.RuneCountInString(k); count > 64 {
+	if count := utf8.RuneCountInString(k); count > 63 {
 		probs = append(probs, &check.Problem{
 			Severity:   check.Problem_ERROR,
-			Message:    fmt.Sprintf(`Key %q exceeds max length of 64 characters.`, k),
+			Message:    fmt.Sprintf(`Key %q exceeds max length of 63 characters.`, k),
 			Suggestion: `Fix key.`,
 		})
 	}
diff --git a/cmd/registry/cmd/check/rules/rules.go b/cmd/registry/cmd/check/rules/rules.go
index 098fa13..83542ca 100644
--- a/cmd/registry/cmd/check/rules/rules.go
+++ b/cmd/registry/cmd/check/rules/rules.go
@@ -37,6 +37,7 @@ import (
 	"github.com/apigee/registry/cmd/registry/cmd/check/rules/rule1000"
 	"github.com/apigee/registry/cmd/registry/cmd/check/rules/rule1001"
 	"github.com/apigee/registry/cmd/registry/cmd/check/rules/rule1002"
+	"github.com/apigee/registry/cmd/registry/cmd/check/rules/rule1003"
 	"github.com/apigee/registry/cmd/registry/cmd/check/rules/rule101"
 	"github.com/apigee/registry/cmd/registry/cmd/check/rules/rule102"
 	"github.com/apigee/registry/cmd/registry/cmd/check/rules/rule103"
@@ -72,6 +73,7 @@ var addRulesFuncs = []addRulesFuncType{
 	rule1000.AddRules,
 	rule1001.AddRules,
 	rule1002.AddRules,
+	rule1003.AddRules,
 }
 
 // Add all rules to the given registry.


Test patch:
diff --git a/cmd/registry/cmd/check/rules/rule109/rule109_test.go b/cmd/registry/cmd/check/rules/rule109/rule109_test.go
index ad27136..9bcdb75 100644
--- a/cmd/registry/cmd/check/rules/rule109/rule109_test.go
+++ b/cmd/registry/cmd/check/rules/rule109/rule109_test.go
@@ -41,7 +41,7 @@ func TestDisplayName(t *testing.T) {
 
 	tooLong := []*check.Problem{{
 		Severity:   check.Problem_ERROR,
-		Message:    fmt.Sprintf("%s exceeds limit of 65 characters.", fieldName),
+		Message:    fmt.Sprintf("%s exceeds limit of 64 characters.", fieldName),
 		Suggestion: fmt.Sprintf("Fix %s.", fieldName)}}
 
 	tests := []struct {
@@ -51,8 +51,8 @@ func TestDisplayName(t *testing.T) {
 	}{
 		{"empty", "", nil},
 		{"invalid", string([]byte{0xff}), bad},
-		{"long", strings.Repeat("x", 65), nil},
-		{"too long", strings.Repeat("y", 66), tooLong},
+		{"long", strings.Repeat("x", 64), nil},
+		{"too long", strings.Repeat("y", 65), tooLong},
 	}
 	for _, test := range tests {
 		t.Run(test.name, func(t *testing.T) {
diff --git a/cmd/registry/cmd/check/rules/rule112/rule112_test.go b/cmd/registry/cmd/check/rules/rule112/rule112_test.go
index d7d41af..d1f3c72 100644
--- a/cmd/registry/cmd/check/rules/rule112/rule112_test.go
+++ b/cmd/registry/cmd/check/rules/rule112/rule112_test.go
@@ -143,15 +143,15 @@ func TestCheckLabel(t *testing.T) {
 				Severity:   check.Problem_ERROR,
 			},
 		}},
-		{"long", strings.Repeat("y", 64), strings.Repeat("y", 64), nil},
-		{"too long", strings.Repeat("n", 65), strings.Repeat("n", 65), []*check.Problem{
+		{"long", strings.Repeat("y", 63), strings.Repeat("y", 63), nil},
+		{"too long", strings.Repeat("n", 64), strings.Repeat("n", 64), []*check.Problem{
 			{
-				Message:    fmt.Sprintf(`Key %q exceeds max length of 64 characters.`, strings.Repeat("n", 65)),
+				Message:    fmt.Sprintf(`Key %q exceeds max length of 63 characters.`, strings.Repeat("n", 64)),
 				Suggestion: "Fix key.",
 				Severity:   check.Problem_ERROR,
 			},
 			{
-				Message:    fmt.Sprintf(`Value for key %q exceeds max length of 64 characters.`, strings.Repeat("n", 65)),
+				Message:    fmt.Sprintf(`Value for key %q exceeds max length of 63 characters.`, strings.Repeat("n", 64)),
 				Suggestion: "Fix value.",
 				Severity:   check.Problem_ERROR,
 			},
diff --git a/cmd/registry/cmd/check/rules/rule113/rule113_test.go b/cmd/registry/cmd/check/rules/rule113/rule113_test.go
index f1a0faa..bd0584f 100644
--- a/cmd/registry/cmd/check/rules/rule113/rule113_test.go
+++ b/cmd/registry/cmd/check/rules/rule113/rule113_test.go
@@ -137,10 +137,10 @@ func TestCheckAnnotation(t *testing.T) {
 				Severity:   check.Problem_ERROR,
 			},
 		}},
-		{"long", strings.Repeat("y", 64), strings.Repeat("y", 64), nil},
-		{"too long", strings.Repeat("n", 65), strings.Repeat("n", 65), []*check.Problem{
+		{"long", strings.Repeat("y", 63), strings.Repeat("y", 63), nil},
+		{"too long", strings.Repeat("n", 64), strings.Repeat("n", 64), []*check.Problem{
 			{
-				Message:    fmt.Sprintf(`Key %q exceeds max length of 64 characters.`, strings.Repeat("n", 65)),
+				Message:    fmt.Sprintf(`Key %q exceeds max length of 63 characters.`, strings.Repeat("n", 64)),
 				Suggestion: "Fix key.",
 				Severity:   check.Problem_ERROR,
 			},