Skip to content

Commit

Permalink
Clone ReplacementContext before passing into test (#2198)
Browse files Browse the repository at this point in the history
## Changes
- Add a new method Clone() on ReplacementContext
- Use it when passing common replacements to test cases.

## Tests
Manually. I have a different branch where this bug manifested and this
change helped.
  • Loading branch information
denik authored Jan 21, 2025
1 parent de5155e commit 34a37cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestAccept(t *testing.T) {
testName := strings.ReplaceAll(dir, "\\", "/")
t.Run(testName, func(t *testing.T) {
t.Parallel()
runTest(t, dir, coverDir, repls)
runTest(t, dir, coverDir, repls.Clone())
})
}
}
Expand Down
5 changes: 5 additions & 0 deletions libs/testdiff/replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"regexp"
"slices"
"strings"

"github.com/databricks/cli/internal/testutil"
Expand Down Expand Up @@ -31,6 +32,10 @@ type ReplacementsContext struct {
Repls []Replacement
}

func (r *ReplacementsContext) Clone() ReplacementsContext {
return ReplacementsContext{Repls: slices.Clone(r.Repls)}
}

func (r *ReplacementsContext) Replace(s string) string {
// QQQ Should probably only replace whole words
for _, repl := range r.Repls {
Expand Down

0 comments on commit 34a37cf

Please sign in to comment.