Clone ReplacementContext before passing into test (#2198)

## 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.
This commit is contained in:
Denis Bilenko 2025-01-21 13:47:34 +01:00 committed by GitHub
parent de5155ed0a
commit 34a37cf4a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -99,7 +99,7 @@ func TestAccept(t *testing.T) {
testName := strings.ReplaceAll(dir, "\\", "/") testName := strings.ReplaceAll(dir, "\\", "/")
t.Run(testName, func(t *testing.T) { t.Run(testName, func(t *testing.T) {
t.Parallel() t.Parallel()
runTest(t, dir, coverDir, repls) runTest(t, dir, coverDir, repls.Clone())
}) })
} }
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"regexp" "regexp"
"slices"
"strings" "strings"
"github.com/databricks/cli/internal/testutil" "github.com/databricks/cli/internal/testutil"
@ -31,6 +32,10 @@ type ReplacementsContext struct {
Repls []Replacement Repls []Replacement
} }
func (r *ReplacementsContext) Clone() ReplacementsContext {
return ReplacementsContext{Repls: slices.Clone(r.Repls)}
}
func (r *ReplacementsContext) Replace(s string) string { func (r *ReplacementsContext) Replace(s string) string {
// QQQ Should probably only replace whole words // QQQ Should probably only replace whole words
for _, repl := range r.Repls { for _, repl := range r.Repls {