Skip to content

Commit

Permalink
Merge pull request #26 from tetratelabs/fix-tcp-regex-sliding-window
Browse files Browse the repository at this point in the history
Fix tcp echo regex validation
  • Loading branch information
chirauki authored Jun 13, 2024
2 parents 9ceaa95 + a6d74d7 commit a0d7866
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions pkg/provider/resource_tcp_echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@ func (r *TCPEchoResource) TCPEcho(ctx context.Context, data *TCPEchoResourceMode
ConsecutiveSuccesses: int(data.ConsecutiveSuccesses.ValueInt64()),
}

firstAttemptRegexValue := ""
regexValueStoredAttempt := 0
previousRegexValue := ""
var persistentResponseRegex *regexp.Regexp
var err error
if data.PersistentResponseRegex.ValueString() != "" {
Expand Down Expand Up @@ -273,15 +272,11 @@ func (r *TCPEchoResource) TCPEcho(ctx context.Context, data *TCPEchoResourceMode
// result := persistentResponseRegex.FindString(string(reply))
tflog.Info(ctx, fmt.Sprintf("Result: %s", result))

// Avoid comparison on first attempt
if regexValueStoredAttempt == 0 {
firstAttemptRegexValue = result
regexValueStoredAttempt = attempt
return true
}
if firstAttemptRegexValue != result {
tflog.Warn(ctx, fmt.Sprintf("Got response %q, which does not match previous attempt %q", result, firstAttemptRegexValue))
diag.AddWarning("Check failed", fmt.Sprintf("Got response %q, which does not match previous attempt %q", result, firstAttemptRegexValue))
if previousRegexValue != result {
tflog.Warn(ctx, fmt.Sprintf("Got response %q, which does not match previous attempt %q", result, previousRegexValue))
diag.AddWarning("Check failed", fmt.Sprintf("Got response %q, which does not match previous attempt %q", result, previousRegexValue))

previousRegexValue = result
return false
}
}
Expand Down

0 comments on commit a0d7866

Please sign in to comment.