Skip to content

Commit

Permalink
add regex for internal path
Browse files Browse the repository at this point in the history
  • Loading branch information
denik committed Dec 17, 2024
1 parent e67e615 commit e0ba806
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"target": "dev",
"environment": "dev",
"terraform": {
"exec_path": "/private/var/folders/5y/9kkdnjw91p11vsqwk0cvmk%NUMID%gp/T/TestDefaultPythonPython_3.%NUMID%/%NUMID%/project_name_$UNIQUE_PRJ/.databricks/bundle/dev/bin/terraform"
"exec_path": "/tmp/.../terraform"
},
"git": {
"bundle_root_path": ".",
Expand Down
12 changes: 8 additions & 4 deletions internal/testcli/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func RequireOutput(t testutil.TestingT, ctx context.Context, args []string, expe
}
}

var (
uuidRegex = regexp.MustCompile(`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}`)
numIdRegex = regexp.MustCompile(`[0-9]{3,}`)
privatePathRegex = regexp.MustCompile(`(/tmp|/private)(/.*?)/(terraform)`)
)

func ReplaceOutput(t testutil.TestingT, ctx context.Context, out string) string {
replacements := GetReplacementsMap(ctx)
if replacements == nil {
Expand All @@ -63,11 +69,9 @@ func ReplaceOutput(t testutil.TestingT, ctx context.Context, out string) string
out = strings.ReplaceAll(out, key, value)
}

uuidRegex := regexp.MustCompile(`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}`)
out = uuidRegex.ReplaceAllString(out, "%UUID%")

numId := regexp.MustCompile(`[0-9]{3,}`)
out = numId.ReplaceAllString(out, "%NUMID%")
out = numIdRegex.ReplaceAllString(out, "%NUMID%")
out = privatePathRegex.ReplaceAllString(out, "/tmp/.../$3")

return out
}
Expand Down

0 comments on commit e0ba806

Please sign in to comment.