Skip to content

Commit

Permalink
Match string using regex
Browse files Browse the repository at this point in the history
  • Loading branch information
domhanak committed Feb 8, 2024
1 parent 0022c6d commit 59a52fe
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"net/url"
"os"
"os/exec"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -101,15 +102,16 @@ func getHealthStatusInContainer(podName string, containerName string, ns string)
output, err := utils.Run(cmd)
Expect(err).NotTo(HaveOccurred())
stringOutput := string(output)
split := strings.Index(stringOutput, "{")
stringOutput = stringOutput[split:]
reg, _ := regexp.Compile("\\{(.*)\\}")
stringOutput = reg.FindString(stringOutput)
fmt.Printf("Found string usin regex: %v\n", stringOutput)
err = json.Unmarshal([]byte(stringOutput), &h)
if err != nil {
fmt.Printf("Error decoding HealthCheck response: %v", err)
fmt.Printf("Error decoding HealthCheck response: %v\n", err)
if e, ok := err.(*json.SyntaxError); ok {
fmt.Printf("syntax error at byte offset %d", e.Offset)
fmt.Printf("Syntax error at byte offset %d\n", e.Offset)
}
fmt.Printf("HealthCheck response: %q", output)
fmt.Printf("HealthCheck response: %q\n", stringOutput)
return nil, fmt.Errorf("failed to execute curl command against health endpoint in container %s:%v with output %s", containerName, err, output)
}
return &h, nil
Expand Down

0 comments on commit 59a52fe

Please sign in to comment.