You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2022/09/14 14:03:12 UTC
[skywalking-infra-e2e] branch func/notEmpty/nil created (now f75836a)
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a change to branch func/notEmpty/nil
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git
at f75836a verifier: notEmpty should be able to handle nil
This branch includes the following new commits:
new f75836a verifier: notEmpty should be able to handle nil
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[skywalking-infra-e2e] 01/01: verifier: notEmpty should be able to handle nil
Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch func/notEmpty/nil
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git
commit f75836a52f1f7055f28881cb928971e5c3a048aa
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Wed Sep 14 22:03:00 2022 +0800
verifier: notEmpty should be able to handle nil
---
internal/components/verifier/funcs.go | 13 ++++++++++---
internal/components/verifier/verifier_test.go | 25 +++++++++++++++++++++++++
2 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/internal/components/verifier/funcs.go b/internal/components/verifier/funcs.go
index 785a7b5..e4925cb 100644
--- a/internal/components/verifier/funcs.go
+++ b/internal/components/verifier/funcs.go
@@ -69,9 +69,16 @@ func sha512encode(s string) string {
return hex.EncodeToString(hash.Sum(nil))
}
-func notEmpty(s string) string {
- if len(strings.TrimSpace(s)) > 0 {
- return s
+func notEmpty(s interface{}) string {
+ if s == nil {
+ return fmt.Sprintf("<%q is empty, wanted is not empty>", s)
+ }
+ switch s := s.(type) {
+ case string:
+ if len(strings.TrimSpace(s)) > 0 {
+ return s
+ }
+ return fmt.Sprintf("<%q is empty, wanted is not empty>", s)
}
return fmt.Sprintf("<%q is empty, wanted is not empty>", s)
}
diff --git a/internal/components/verifier/verifier_test.go b/internal/components/verifier/verifier_test.go
index 09da74c..167b5d1 100644
--- a/internal/components/verifier/verifier_test.go
+++ b/internal/components/verifier/verifier_test.go
@@ -271,6 +271,31 @@ metrics:
`,
},
wantErr: false,
+ }, {
+ name: "notEmpty with nil",
+ args: args{
+ actualData: `
+- key: 0
+ value:
+ - key: name
+ value: SET TIMESTAMP
+ - key: id
+ value: "123"
+ - key: refid
+ value: null
+ `,
+ expectedTemplate: `
+{{- contains . }}
+- key: 0
+ value:
+ {{- contains .value }}
+ - key: {{ notEmpty .key }}
+ value: {{ notEmpty .value }}
+ {{- end }}
+{{- end }}
+ `,
+ },
+ wantErr: false,
},
}
for _, tt := range tests {