From 34a37cf4a8d7248bce2c2291018c6d02c217c653 Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Tue, 21 Jan 2025 13:47:34 +0100 Subject: [PATCH] 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. --- acceptance/acceptance_test.go | 2 +- libs/testdiff/replacement.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 850d3bf9d..12fe6536f 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -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()) }) } } diff --git a/libs/testdiff/replacement.go b/libs/testdiff/replacement.go index 1ab976109..207f425aa 100644 --- a/libs/testdiff/replacement.go +++ b/libs/testdiff/replacement.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "regexp" + "slices" "strings" "github.com/databricks/cli/internal/testutil" @@ -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 {