Skip to content

Commit 0af9cf4

Browse files
committed
feat(testing/v2): init
1 parent d800f2c commit 0af9cf4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2253
-1003
lines changed

anyjson/op__diff_test.go

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,79 @@ package anyjson_test
33
import (
44
"testing"
55

6-
. "github.com/octohelm/x/anyjson"
7-
testingx "github.com/octohelm/x/testing"
6+
"github.com/octohelm/x/anyjson"
7+
. "github.com/octohelm/x/testing/v2"
88
)
99

1010
func TestDiff(t *testing.T) {
1111
t.Run("normal diff", func(t *testing.T) {
12-
base := MustFromValue(Obj{
13-
"int_changed": 1,
14-
"str_not_changed": "string",
15-
"list_not_changed": List{"1", "2"},
16-
"list_changed": List{"2"},
17-
"bool_not_exists_as_changed": true,
18-
}).(*Object)
12+
base := MustValue(t, func() (*Object, error) {
13+
v, err := anyjson.FromValue(Obj{
14+
"int_changed": 1,
15+
"str_not_changed": "string",
16+
"list_not_changed": List{"1", "2"},
17+
"list_changed": List{"2"},
18+
"bool_not_exists_as_changed": true,
19+
})
20+
return v.(*Object), err
21+
})
1922

20-
target := MustFromValue(Obj{
21-
"int_changed": 2,
22-
"str_not_changed": "string",
23-
"list_not_changed": List{"1", "2"},
24-
"list_changed": List{"1"},
25-
}).(*Object)
23+
target := MustValue(t, func() (*Object, error) {
24+
v, err := anyjson.FromValue(Obj{
25+
"int_changed": 2,
26+
"str_not_changed": "string",
27+
"list_not_changed": List{"1", "2"},
28+
"list_changed": List{"1"},
29+
})
30+
return v.(*Object), err
31+
})
2632

27-
diffed, err := Diff(base, target)
28-
testingx.Expect(t, err, testingx.Be[error](nil))
33+
diffed := MustValue(t, func() (anyjson.Valuer, error) {
34+
return anyjson.Diff(base, target)
35+
})
2936

30-
testingx.Expect(t, diffed.Value(), testingx.Equal[any](Obj{
31-
"int_changed": 2,
32-
"list_changed": List{"1"},
33-
"bool_not_exists_as_changed": false,
34-
}))
37+
Then(t, "diff should contain only changed fields",
38+
Expect(diffed.Value(), Equal[any](Obj{
39+
"int_changed": 2,
40+
"list_changed": List{"1"},
41+
"bool_not_exists_as_changed": false,
42+
})),
43+
)
3544
})
3645

3746
t.Run("array object diff", func(t *testing.T) {
38-
t.Run("array object merge", func(t *testing.T) {
39-
base := MustFromValue(Obj{
47+
base := MustValue(t, func() (*Object, error) {
48+
v, err := anyjson.FromValue(Obj{
4049
"withMergeKey": List{
41-
Obj{
42-
"name": "a",
43-
"value": "x",
44-
},
45-
Obj{
46-
"name": "b",
47-
"value": "x",
48-
},
50+
Obj{"name": "a", "value": "x"},
51+
Obj{"name": "b", "value": "x"},
4952
},
5053
"withoutMergeKey": List{
51-
Obj{
52-
"value": "1",
53-
},
54+
Obj{"value": "1"},
5455
},
55-
}).(*Object)
56+
})
57+
return v.(*Object), err
58+
})
5659

57-
target := MustFromValue(Obj{
60+
target := MustValue(t, func() (*Object, error) {
61+
v, err := anyjson.FromValue(Obj{
5862
"withMergeKey": List{
59-
Obj{
60-
"name": "a",
61-
"value": "patched",
62-
},
63-
Obj{
64-
"name": "c",
65-
"value": "new",
66-
},
63+
Obj{"name": "a", "value": "patched"},
64+
Obj{"name": "c", "value": "new"},
6765
},
6866
"withoutMergeKey": List{
69-
Obj{
70-
"value": "2",
71-
},
67+
Obj{"value": "2"},
7268
},
73-
}).(*Object)
69+
})
70+
return v.(*Object), err
71+
})
7472

75-
diffed, err := Diff(base, target)
76-
testingx.Expect(t, err, testingx.Be[error](nil))
73+
diffed := MustValue(t, func() (anyjson.Valuer, error) {
74+
return anyjson.Diff(base, target)
75+
})
7776

78-
testingx.Expect(t, diffed.Value(), testingx.Equal[any](Obj{
77+
Then(t, "should generate patch with delete and add operations",
78+
Expect(diffed.Value(), Equal[any](Obj{
7979
"withMergeKey": List{
8080
Obj{
8181
"name": "a",
@@ -95,7 +95,7 @@ func TestDiff(t *testing.T) {
9595
"value": "2",
9696
},
9797
},
98-
}))
99-
})
98+
})),
99+
)
100100
})
101101
}

0 commit comments

Comments
 (0)