add subtests

reorganize some SMP tests to make them easier to target via go run patterns
This commit is contained in:
Alexander Zielenski 2023-04-22 11:03:57 -07:00
parent 95fea2f2bf
commit e00a9c3a0b

View File

@ -738,17 +738,21 @@ func TestCustomStrategicMergePatch(t *testing.T) {
return
}
for _, schema := range schemas {
for _, c := range tc.TestCases {
t.Run(c.Description, func(t *testing.T) {
for _, schema := range schemas {
t.Run(schema.Name(), func(t *testing.T) {
original, expectedTwoWayPatch, _, expectedResult := twoWayTestCaseToJSONOrFail(t, c, schema)
testPatchApplication(t, original, expectedTwoWayPatch, expectedResult, c.Description, "", schema)
}
})
for _, c := range customStrategicMergePatchRawTestCases {
original, expectedTwoWayPatch, _, expectedResult := twoWayRawTestCaseToJSONOrFail(t, c)
testPatchApplication(t, original, expectedTwoWayPatch, expectedResult, c.Description, c.ExpectedError, schema)
}
}
})
}
}
// These are test cases for StrategicMergePatch, to assert that applying a patch
@ -6140,6 +6144,8 @@ func TestStrategicMergePatch(t *testing.T) {
}
for _, schema := range schemas {
t.Run(schema.Name(), func(t *testing.T) {
testStrategicMergePatchWithCustomArguments(t, "bad original",
"<THIS IS NOT JSON>", "{}", schema, mergepatch.ErrBadJSONDoc)
testStrategicMergePatchWithCustomArguments(t, "bad patch",
@ -6148,15 +6154,24 @@ func TestStrategicMergePatch(t *testing.T) {
"{}", "{}", nil, mergepatch.ErrBadArgKind(struct{}{}, nil))
for _, c := range tc.TestCases {
t.Run(c.Description+"/TwoWay", func(t *testing.T) {
testTwoWayPatch(t, c, schema)
})
t.Run(c.Description+"/ThreeWay", func(t *testing.T) {
testThreeWayPatch(t, c, schema)
})
}
})
// run multiple times to exercise different map traversal orders
for i := 0; i < 10; i++ {
for _, c := range strategicMergePatchRawTestCases {
t.Run(c.Description+"/TwoWay", func(t *testing.T) {
testTwoWayPatchForRawTestCase(t, c, schema)
})
t.Run(c.Description+"/ThreeWay", func(t *testing.T) {
testThreeWayPatchForRawTestCase(t, c, schema)
})
}
}
}
@ -6899,9 +6914,10 @@ func TestUnknownField(t *testing.T) {
}
for _, k := range sets.StringKeySet(testcases).List() {
t.Run(k, func(t *testing.T) {
tc := testcases[k]
for _, schema := range schemas {
func() {
t.Run(schema.Name()+"/TwoWay", func(t *testing.T) {
twoWay, err := CreateTwoWayMergePatchUsingLookupPatchMeta([]byte(tc.Original), []byte(tc.Modified), schema)
if err != nil {
if len(tc.ExpectedTwoWayErr) == 0 {
@ -6927,9 +6943,9 @@ func TestUnknownField(t *testing.T) {
t.Errorf("using %s in testcase %s: expected two-way result:\n\t%s\ngot\n\t%s", getSchemaType(schema), k, string(tc.ExpectedTwoWayResult), string(twoWayResult))
return
}
}()
})
func() {
t.Run(schema.Name()+"/ThreeWay", func(t *testing.T) {
threeWay, err := CreateThreeWayMergePatch([]byte(tc.Original), []byte(tc.Modified), []byte(tc.Current), schema, false)
if err != nil {
if len(tc.ExpectedThreeWayErr) == 0 {
@ -6953,7 +6969,8 @@ func TestUnknownField(t *testing.T) {
t.Errorf("using %s in testcase %s: expected three-way result:\n\t%s\ngot\n\t%s", getSchemaType(schema), k, string(tc.ExpectedThreeWayResult), string(threeWayResult))
return
}
}()
}
})
}
})
}
}