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 2021/10/14 02:48:08 UTC

[skywalking-infra-e2e] branch main updated: Using including file path as included cases' `expect/actual` base path (#54)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 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 44d4370  Using including file path as included cases' `expect/actual` base path (#54)
44d4370 is described below

commit 44d43701de508462878733ea9999dd6d963bc7af
Author: mrproliu <74...@qq.com>
AuthorDate: Thu Oct 14 10:48:00 2021 +0800

    Using including file path as included cases' `expect/actual` base path (#54)
---
 internal/config/globalConfig.go | 18 ++++++++++++++----
 internal/util/config.go         | 16 ++++++++++------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/internal/config/globalConfig.go b/internal/config/globalConfig.go
index 1eaf198..7be0ae9 100644
--- a/internal/config/globalConfig.go
+++ b/internal/config/globalConfig.go
@@ -22,6 +22,7 @@ import (
 	"fmt"
 	"io/ioutil"
 	"os"
+	"path/filepath"
 
 	"github.com/apache/skywalking-infra-e2e/internal/constant"
 	"github.com/apache/skywalking-infra-e2e/internal/logger"
@@ -76,8 +77,9 @@ func ReadGlobalConfigFile() {
 func convertVerify(verify *Verify) error {
 	// convert cases
 	result := make([]VerifyCase, 0)
+	cfgAbsPath, _ := filepath.Abs(util.CfgFile)
 	for _, c := range verify.Cases {
-		cases, err := convertSingleCase(c)
+		cases, err := convertSingleCase(c, cfgAbsPath)
 		if err != nil {
 			return err
 		}
@@ -87,16 +89,23 @@ func convertVerify(verify *Verify) error {
 	return nil
 }
 
-func convertSingleCase(verifyCase VerifyCase) ([]VerifyCase, error) {
+func convertSingleCase(verifyCase VerifyCase, baseFile string) ([]VerifyCase, error) {
 	if len(verifyCase.Includes) > 0 && (verifyCase.Expected != "" || verifyCase.Query != "") {
 		return nil, fmt.Errorf("include and query/expected only support selecting one of them in a case")
 	}
 	if len(verifyCase.Includes) == 0 {
+		// using base path to resolve case paths
+		if verifyCase.Expected != "" {
+			verifyCase.Expected = util.ResolveAbsWithBase(verifyCase.Expected, baseFile)
+		}
+		if verifyCase.Actual != "" {
+			verifyCase.Actual = util.ResolveAbsWithBase(verifyCase.Actual, baseFile)
+		}
 		return []VerifyCase{verifyCase}, nil
 	}
 	result := make([]VerifyCase, 0)
 	for _, include := range verifyCase.Includes {
-		includePath := util.ResolveAbs(include)
+		includePath := util.ResolveAbsWithBase(include, baseFile)
 
 		if !util.PathExist(includePath) {
 			return nil, fmt.Errorf("reuse case config file %s not exist", includePath)
@@ -113,7 +122,8 @@ func convertSingleCase(verifyCase VerifyCase) ([]VerifyCase, error) {
 		}
 
 		for _, c := range r.Cases {
-			cases, err := convertSingleCase(c)
+			// using include file path as base path to resolve cases
+			cases, err := convertSingleCase(c, includePath)
 			if err != nil {
 				return nil, err
 			}
diff --git a/internal/util/config.go b/internal/util/config.go
index c34eecb..679235d 100644
--- a/internal/util/config.go
+++ b/internal/util/config.go
@@ -32,19 +32,23 @@ var (
 
 // ResolveAbs resolves the relative path (relative to CfgFile) to an absolute file path.
 func ResolveAbs(p string) string {
-	if p == "" {
+	abs, err := filepath.Abs(CfgFile)
+	if err != nil {
+		logger.Log.Warnf("failed to resolve the absolute file path of %v\n", CfgFile)
 		return p
 	}
+	return ResolveAbsWithBase(p, abs)
+}
 
-	if path.IsAbs(p) {
+// ResolveAbsWithBase resolves the relative path (relative to appoint file path) to an absolute file path.
+func ResolveAbsWithBase(p, baseFile string) string {
+	if p == "" {
 		return p
 	}
 
-	abs, err := filepath.Abs(CfgFile)
-	if err != nil {
-		logger.Log.Warnf("failed to resolve the absolute file path of %v\n", CfgFile)
+	if path.IsAbs(p) {
 		return p
 	}
 
-	return filepath.Join(filepath.Dir(abs), p)
+	return filepath.Join(filepath.Dir(baseFile), p)
 }