You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/08/07 12:39:34 UTC
[skywalking-infra-e2e] branch main updated: Improve features for
verify (#27)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-infra-e2e.git
The following commit(s) were added to refs/heads/main by this push:
new e6651c0 Improve features for verify (#27)
e6651c0 is described below
commit e6651c049a5858a4b5a30f76ee1b3bc910a9cac8
Author: mrproliu <74...@qq.com>
AuthorDate: Sat Aug 7 20:39:30 2021 +0800
Improve features for verify (#27)
* let contains condition support multiple level attribute, show error message when template error
* Add test case and fix add indent way
---
commands/verify/verify.go | 2 +-
internal/components/verifier/verifier_test.go | 56 +++++++++++++++++++++++++++
third-party/go/template/exec.go | 8 ++++
3 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/commands/verify/verify.go b/commands/verify/verify.go
index 3307f43..3f5146a 100644
--- a/commands/verify/verify.go
+++ b/commands/verify/verify.go
@@ -78,7 +78,7 @@ func verifySingleCase(expectedFile, actualFile, query string) error {
if me, ok := err.(*verifier.MismatchError); ok {
return fmt.Errorf("failed to verify the output: %s, error: %v", sourceName, me.Error())
}
- return fmt.Errorf("failed to verify the output: %s", sourceName)
+ return fmt.Errorf("failed to verify the output: %s, error: %v", sourceName, err)
}
logger.Log.Infof("verified the output: %s\n", sourceName)
return nil
diff --git a/internal/components/verifier/verifier_test.go b/internal/components/verifier/verifier_test.go
index 0d6b7e7..d2a287c 100644
--- a/internal/components/verifier/verifier_test.go
+++ b/internal/components/verifier/verifier_test.go
@@ -139,6 +139,62 @@ metrics:
},
wantErr: true,
},
+ {
+ name: "multiple level attribute and contains greater and equals 2",
+ args: args{
+ actualData: `
+metrics:
+ key:
+ - name: business-zone::projectA
+ id: YnVzaW5lc3Mtem9uZTo6cHJvamVjdEE=.1
+ value: 1
+ - name: system::load balancer1
+ id: c3lzdGVtOjpsb2FkIGJhbGFuY2VyMQ==.1
+ value: 0
+ - name: system::load balancer2
+ id: WW91cl9BcHBsaWNhdGlvbk5hbWU=.1
+ value: 2
+`,
+ expectedTemplate: `
+metrics:
+ key:
+ {{- contains .metrics.key }}
+ - name: {{ notEmpty .name }}
+ id: {{ notEmpty .id }}
+ value: {{ ge .value 2 }}
+ {{- end }}
+`,
+ },
+ wantErr: false,
+ },
+ {
+ name: "multiple level attribute and contains greater 2",
+ args: args{
+ actualData: `
+metrics:
+ key:
+ - name: business-zone::projectA
+ id: YnVzaW5lc3Mtem9uZTo6cHJvamVjdEE=.1
+ value: 1
+ - name: system::load balancer1
+ id: c3lzdGVtOjpsb2FkIGJhbGFuY2VyMQ==.1
+ value: 0
+ - name: system::load balancer2
+ id: WW91cl9BcHBsaWNhdGlvbk5hbWU=.1
+ value: 2
+`,
+ expectedTemplate: `
+metrics:
+ key:
+ {{- contains .metrics.key }}
+ - name: {{ notEmpty .name }}
+ id: {{ notEmpty .id }}
+ value: {{ gt .value 2 }}
+ {{- end }}
+`,
+ },
+ wantErr: true,
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
diff --git a/third-party/go/template/exec.go b/third-party/go/template/exec.go
index 0d88f70..24ff03d 100644
--- a/third-party/go/template/exec.go
+++ b/third-party/go/template/exec.go
@@ -456,6 +456,11 @@ func (s *state) walkContains(dot reflect.Value, r *parse.ContainsNode) {
}
}
+ var addRootIndent = func(b []byte, n int) []byte {
+ prefix := append([]byte("\n"), bytes.Repeat([]byte(" "), n)...)
+ b = append(prefix[1:], b...) // Indent first line
+ return bytes.ReplaceAll(b, []byte("\n"), prefix)
+ }
var marshal []byte
if len(matched) == expectedSize {
value, _ := printableValue(val)
@@ -463,6 +468,9 @@ func (s *state) walkContains(dot reflect.Value, r *parse.ContainsNode) {
} else {
marshal, _ = yaml.Marshal(output)
}
+
+ listTokenIndex := strings.Index(strings.TrimPrefix(r.List.Nodes[0].String(), "\n"), "-")
+ marshal = addRootIndent(marshal, listTokenIndex)
s.wr.Write(append([]byte("\n"), marshal...))
return
case reflect.Map: