File tree 2 files changed +15
-2
lines changed
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -232,13 +232,14 @@ var testCases = []struct {
232
232
func TestMain (t * testing.T ) {
233
233
for _ , tc := range testCases {
234
234
t .Run (tc .description , func (t * testing.T ) {
235
- app := NewApp ("randomizer" , tc .store )
235
+ store := tc .store .Clone ()
236
+ app := NewApp ("randomizer" , store )
236
237
app .shuffle = slices .Sort
237
238
238
239
res , err := app .Main (context .Background (), tc .args )
239
240
tc .check (t , res , err )
240
241
241
- if tc .expectedStore != nil && ! reflect .DeepEqual (tc . store , tc .expectedStore ) {
242
+ if tc .expectedStore != nil && ! reflect .DeepEqual (store , tc .expectedStore ) {
242
243
t .Errorf ("unexpected store state\n got: %v\n want: %v" , tc .store , tc .expectedStore )
243
244
}
244
245
})
Original file line number Diff line number Diff line change @@ -12,6 +12,18 @@ import (
12
12
// strings. A nil Store will return errors for every operation.
13
13
type Store map [string ][]string
14
14
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
+
15
27
// List implements randomizer.Store.
16
28
func (s Store ) List (_ context.Context ) ([]string , error ) {
17
29
if s == nil {
You can’t perform that action at this time.
0 commit comments