File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -232,13 +232,14 @@ var testCases = []struct {
232232func TestMain (t * testing.T ) {
233233 for _ , tc := range testCases {
234234 t .Run (tc .description , func (t * testing.T ) {
235- app := NewApp ("randomizer" , tc .store )
235+ store := tc .store .Clone ()
236+ app := NewApp ("randomizer" , store )
236237 app .shuffle = slices .Sort
237238
238239 res , err := app .Main (context .Background (), tc .args )
239240 tc .check (t , res , err )
240241
241- if tc .expectedStore != nil && ! reflect .DeepEqual (tc . store , tc .expectedStore ) {
242+ if tc .expectedStore != nil && ! reflect .DeepEqual (store , tc .expectedStore ) {
242243 t .Errorf ("unexpected store state\n got: %v\n want: %v" , tc .store , tc .expectedStore )
243244 }
244245 })
Original file line number Diff line number Diff line change @@ -12,6 +12,18 @@ import (
1212// strings. A nil Store will return errors for every operation.
1313type Store map [string ][]string
1414
15+ // Clone returns a deep copy of the original store.
16+ func (s Store ) Clone () Store {
17+ if s == nil {
18+ return nil
19+ }
20+ out := make (Store , len (s ))
21+ for k , v := range s {
22+ out [k ] = slices .Clone (v )
23+ }
24+ return out
25+ }
26+
1527// List implements randomizer.Store.
1628func (s Store ) List (_ context.Context ) ([]string , error ) {
1729 if s == nil {
You can’t perform that action at this time.
0 commit comments