use regex for vm output and expected content

This commit is contained in:
2024-10-09 12:18:56 +03:00
parent 3d409a7a59
commit 1d67fb694b
3 changed files with 72 additions and 13 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"log"
"os"
"regexp"
)
type Step struct {
@@ -11,6 +12,19 @@ type Step struct {
ExpectedContent string `json:"expectedContent"`
}
func (s *Step) MatchesExpectedContent(content []byte) (bool, error) {
pattern := `.*\?.*|.*`
re, err := regexp.Compile(pattern)
if err != nil {
return false, err
}
// Check if the content matches the regex pattern
if re.Match(content) {
return true, nil
}
return false, nil
}
// Group represents a group of steps
type Group struct {
Name string `json:"name"`
@@ -23,6 +37,18 @@ type TestCase struct {
ExpectedContent string
}
func (s *TestCase) MatchesExpectedContent(content []byte) (bool, error) {
re, err := regexp.Compile(s.ExpectedContent)
if err != nil {
return false, err
}
// Check if the content matches the regex pattern
if re.Match(content) {
return true, nil
}
return false, nil
}
// DataGroup represents the overall structure of the JSON.
type DataGroup struct {
Groups []Group `json:"groups"`