-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifiers_test.go
43 lines (32 loc) · 1.15 KB
/
modifiers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package gosl
import (
"testing"
"github.com/stretchr/testify/assert"
)
func BenchmarkModifyByValue(b *testing.B) {
for i := 0; i < b.N; i++ {
m := map[string]any{"order": map[string]any{"tags": "new"}}
foundValue := "new"
newValue := "paid"
_, _ = ModifyByValue(m, foundValue, newValue)
}
}
func TestModifyByValue(t *testing.T) {
foundValue := "new"
newValue := "paid"
isFound, result := ModifyByValue(nil, foundValue, newValue)
assert.EqualValues(t, isFound, false)
m := map[string]any{"order": map[string]any{"tags": "new"}}
modified := map[string]any{"order": map[string]any{"tags": "paid"}}
isFound, result = ModifyByValue(m, foundValue, newValue)
assert.EqualValues(t, isFound, true)
assert.EqualValues(t, result, modified)
u := Utility{} // tests for method
isFound2, result2 := u.ModifyByValue(nil, foundValue, newValue)
assert.EqualValues(t, isFound2, false)
m2 := map[string]any{"order": map[string]any{"tags": "new"}}
modified2 := map[string]any{"order": map[string]any{"tags": "paid"}}
isFound2, result2 = u.ModifyByValue(m2, foundValue, newValue)
assert.EqualValues(t, isFound2, true)
assert.EqualValues(t, result2, modified2)
}