Repository: go-kratos/kratos
Pull request #2443 (2022-10-13 03:28:56)

test(middleware/logging): TestExtractError

codecov-commenter: # [Codecov](https://codecov.io/gh/go-kratos/kratos/pull/2443?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-kratos) Report
> Merging [#2443](https://codecov.io/gh/go-kratos/kratos/pull/2443?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-kratos) (e3416a4) into [main](https://codecov.io/gh/go-kratos/kratos/commit/b5cd1c693d046a443a0cbcae767e57fbfa416390?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-kratos) (b5cd1c6) will **not change** coverage.
> The diff coverage is `n/a`.

> :exclamation: Current head e3416a4 differs from pull request most recent head 047f581. Consider uploading reports for the commit 047f581 to get more accurate results

```diff
@@           Coverage Diff           @@
##             main    #2443   +/-   ##
=======================================
  Coverage   84.95%   84.95%           
=======================================
  Files          88       88           
  Lines        3788     3788           
=======================================
  Hits         3218     3218           
  Misses        402      402           
  Partials      168      168           
```



Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-kratos). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=go-kratos)


Patch:
diff --git a/cmd/kratos/internal/base/vcs_url.go b/cmd/kratos/internal/base/vcs_url.go
index ef76db30..6d3aef12 100644
--- a/cmd/kratos/internal/base/vcs_url.go
+++ b/cmd/kratos/internal/base/vcs_url.go
@@ -8,7 +8,7 @@ import (
 )
 
 var (
-	scpSyntaxRe = regexp.MustCompile(`^([a-zA-Z0-9_]+)@([a-zA-Z0-9._-]+):(.*)$`)
+	scpSyntaxRe = regexp.MustCompile(`^(\w+)@([\w.-]+):(.*)$`)
 	scheme      = []string{"git", "https", "http", "git+ssh", "ssh", "file", "ftp", "ftps"}
 )
 


Test patch:
diff --git a/middleware/logging/logging_test.go b/middleware/logging/logging_test.go
index 6ad1a02c..431d8901 100644
--- a/middleware/logging/logging_test.go
+++ b/middleware/logging/logging_test.go
@@ -111,7 +111,7 @@ func (d *dummyStringer) String() string {
 	return "my value"
 }
 
-func Test_extractArgs(t *testing.T) {
+func TestExtractArgs(t *testing.T) {
 	if extractArgs(&dummyStringer{field: ""}) != "my value" {
 		t.Errorf(`The stringified dummyStringer structure must be equal to "my value", %v given`, extractArgs(&dummyStringer{field: ""}))
 	}
@@ -120,3 +120,30 @@ func Test_extractArgs(t *testing.T) {
 		t.Errorf(`The stringified dummy structure must be equal to "&{field:value}", %v given`, extractArgs(&dummy{field: "value"}))
 	}
 }
+
+func TestExtractError(t *testing.T) {
+	tests := []struct {
+		name       string
+		err        error
+		wantLevel  log.Level
+		wantErrStr string
+	}{
+		{
+			"no error", nil, log.LevelInfo, "",
+		},
+		{
+			"error", errors.New("test error"), log.LevelError, "test error",
+		},
+	}
+	for _, test := range tests {
+		t.Run(test.name, func(t *testing.T) {
+			level, errStr := extractError(test.err)
+			if level != test.wantLevel {
+				t.Errorf("want: %d, got: %d", test.wantLevel, level)
+			}
+			if errStr != test.wantErrStr {
+				t.Errorf("want: %s, got: %s", test.wantErrStr, errStr)
+			}
+		})
+	}
+}