You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2021/03/19 12:19:13 UTC

[plc4x] branch develop updated: plc4go: Improved ParserSerializerTestRunner.go with sub-test and skip + Testcases are now properly reported as sub tests + Added ability to skip test cases

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

sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/develop by this push:
     new a2197a2  plc4go: Improved ParserSerializerTestRunner.go with sub-test and skip + Testcases are now properly reported as sub tests + Added ability to skip test cases
a2197a2 is described below

commit a2197a2ffbeb91be44c41384abd5684d6fc994b8
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri Mar 19 13:18:56 2021 +0100

    plc4go: Improved ParserSerializerTestRunner.go with sub-test and skip
    + Testcases are now properly reported as sub tests
    + Added ability to skip test cases
---
 .../spi/testutils/ParserSerializerTestRunner.go    | 163 +++++++++++----------
 1 file changed, 88 insertions(+), 75 deletions(-)

diff --git a/plc4go/internal/plc4go/spi/testutils/ParserSerializerTestRunner.go b/plc4go/internal/plc4go/spi/testutils/ParserSerializerTestRunner.go
index 6b31df5..ecf6048 100644
--- a/plc4go/internal/plc4go/spi/testutils/ParserSerializerTestRunner.go
+++ b/plc4go/internal/plc4go/spi/testutils/ParserSerializerTestRunner.go
@@ -24,6 +24,7 @@ import (
 	"fmt"
 	model2 "github.com/apache/plc4x/plc4go/internal/plc4go/modbus/readwrite"
 	"github.com/apache/plc4x/plc4go/internal/plc4go/spi/utils"
+	"github.com/rs/zerolog/log"
 	"github.com/subchen/go-xmldom"
 	"os"
 	"strconv"
@@ -31,7 +32,11 @@ import (
 	"testing"
 )
 
-func RunParserSerializerTestsuite(t *testing.T, testPath string) {
+func RunParserSerializerTestsuite(t *testing.T, testPath string, skippedTestCases ...string) {
+	skippedTestCasesMap := map[string]bool{}
+	for _, skippedTestCase := range skippedTestCases {
+		skippedTestCasesMap[skippedTestCase] = true
+	}
 	// Get the current working directory
 	path, err := os.Getwd()
 	if err != nil {
@@ -69,91 +74,99 @@ func RunParserSerializerTestsuite(t *testing.T, testPath string) {
 			t.Error("Invalid document structure")
 			curFailed = true
 		} else {
-			t.Logf("running testsuite: %s test: %s", testsuiteName, (*(child.FindOneByName("name"))).Text)
-			rawInputText := (*(child.FindOneByName("raw"))).Text
-			rootType := (*(child.FindOneByName("root-type"))).Text
-			parserArgumentsXml := child.FindOneByName("parser-arguments")
-			var parserArguments []string
-			if parserArgumentsXml != nil {
-				for _, parserArgumentXml := range parserArgumentsXml.Children {
-					parserArguments = append(parserArguments, parserArgumentXml.Text)
+			testCaseName := child.FindOneByName("name").Text
+			t.Run(testCaseName, func(t *testing.T) {
+				if skippedTestCasesMap[testCaseName] {
+					log.Warn().Msgf("Testcase %s skipped", testCaseName)
+					t.Skipf("Testcase %s skipped", testCaseName)
+					return
+				}
+				t.Logf("running testsuite: %s test: %s", testsuiteName, testCaseName)
+				rawInputText := (*(child.FindOneByName("raw"))).Text
+				rootType := (*(child.FindOneByName("root-type"))).Text
+				parserArgumentsXml := child.FindOneByName("parser-arguments")
+				var parserArguments []string
+				if parserArgumentsXml != nil {
+					for _, parserArgumentXml := range parserArgumentsXml.Children {
+						parserArguments = append(parserArguments, parserArgumentXml.Text)
+					}
 				}
-			}
-			referenceXml := child.FindOneByName("xml")
-			normalizeXml(referenceXml)
-			referenceSerialized := referenceXml.FirstChild().XML()
+				referenceXml := child.FindOneByName("xml")
+				normalizeXml(referenceXml)
+				referenceSerialized := referenceXml.FirstChild().XML()
 
-			// Get the raw input by decoding the hex-encoded binary input
-			rawInput, err := hex.DecodeString(rawInputText)
-			if err != nil {
-				t.Errorf("Error decoding test input")
-				t.Fail()
-				curFailed = true
-			}
-			readBuffer := utils.NewReadBuffer(rawInput)
+				// Get the raw input by decoding the hex-encoded binary input
+				rawInput, err := hex.DecodeString(rawInputText)
+				if err != nil {
+					t.Errorf("Error decoding test input")
+					t.Fail()
+					curFailed = true
+				}
+				readBuffer := utils.NewReadBuffer(rawInput)
 
-			// Parse the input according to the settings of the testcase
-			helper := new(model2.ModbusParserHelper)
-			msg, err := helper.Parse(rootType, parserArguments, readBuffer)
-			if err != nil {
-				t.Error("Error parsing input data: " + err.Error())
-				t.Fail()
-				curFailed = true
-			}
+				// Parse the input according to the settings of the testcase
+				helper := new(model2.ModbusParserHelper)
+				msg, err := helper.Parse(rootType, parserArguments, readBuffer)
+				if err != nil {
+					t.Error("Error parsing input data: " + err.Error())
+					t.Fail()
+					curFailed = true
+				}
 
-			// Serialize the parsed object to XML
-			actualSerialized, err := xml.Marshal(msg)
-			if err != nil {
-				t.Error("Error serializing the actual message: " + err.Error())
-				t.Fail()
-				curFailed = true
-			}
+				// Serialize the parsed object to XML
+				actualSerialized, err := xml.Marshal(msg)
+				if err != nil {
+					t.Error("Error serializing the actual message: " + err.Error())
+					t.Fail()
+					curFailed = true
+				}
 
-			// Compare the actual and the expected xml
-			err = CompareResults(actualSerialized, []byte(referenceSerialized))
-			if err != nil {
-				t.Error("Error comparing the results: " + err.Error())
-				t.Fail()
-				curFailed = true
-			}
+				// Compare the actual and the expected xml
+				err = CompareResults(actualSerialized, []byte(referenceSerialized))
+				if err != nil {
+					t.Error("Error comparing the results: " + err.Error())
+					t.Fail()
+					curFailed = true
+				}
 
-			// If all was ok, serialize the object again
-			s, ok := msg.(utils.Serializable)
-			if !ok {
-				t.Error("Couldn't cast message to Serializable")
-				t.Fail()
-				curFailed = true
-			}
-			writeBuffer := utils.NewWriteBuffer()
-			err = s.Serialize(*writeBuffer)
-			if !ok {
-				t.Error("Couldn't serialize message back to byte array")
-				t.Fail()
-				curFailed = true
-			}
+				// If all was ok, serialize the object again
+				s, ok := msg.(utils.Serializable)
+				if !ok {
+					t.Error("Couldn't cast message to Serializable")
+					t.Fail()
+					curFailed = true
+				}
+				writeBuffer := utils.NewWriteBuffer()
+				err = s.Serialize(*writeBuffer)
+				if !ok {
+					t.Error("Couldn't serialize message back to byte array")
+					t.Fail()
+					curFailed = true
+				}
 
-			// Check if the output matches in size and content
-			rawOutput := writeBuffer.GetBytes()
-			if len(rawInput) != len(rawOutput) {
-				t.Error("Couldn't serialize message back to byte array")
-				t.Fail()
-				curFailed = true
-			}
-			for i, val := range rawInput {
-				if rawOutput[i] != val {
-					t.Error("Raw output doesn't match input at position: " + strconv.Itoa(i))
+				// Check if the output matches in size and content
+				rawOutput := writeBuffer.GetBytes()
+				if len(rawInput) != len(rawOutput) {
+					t.Error("Couldn't serialize message back to byte array")
 					t.Fail()
 					curFailed = true
 				}
-			}
+				for i, val := range rawInput {
+					if rawOutput[i] != val {
+						t.Error("Raw output doesn't match input at position: " + strconv.Itoa(i))
+						t.Fail()
+						curFailed = true
+					}
+				}
 
-			if curFailed {
-				// All worked
-				t.Logf("FAILED")
-			} else {
-				// All worked
-				t.Logf("SUCCESS")
-			}
+				if curFailed {
+					// All worked
+					t.Logf("FAILED")
+				} else {
+					// All worked
+					t.Logf("SUCCESS")
+				}
+			})
 		}
 	}
 	fmt.Printf("name = %v\n", node.Name)