Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in SMP test #46146

Merged
merged 1 commit into from
May 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,11 @@ func TestSortMergeLists(t *testing.T) {
}

for _, c := range tc.TestCases {
original := testObjectToJSONOrFail(t, c.Original, c.Description)
sorted := testObjectToJSONOrFail(t, c.Sorted, c.Description)
if !reflect.DeepEqual(original, sorted) {
got := sortJsonOrFail(t, testObjectToJSONOrFail(t, c.Original), c.Description)
expected := testObjectToJSONOrFail(t, c.Sorted)
if !reflect.DeepEqual(got, expected) {
t.Errorf("error in test case: %s\ncannot sort object:\n%s\nexpected:\n%s\ngot:\n%s\n",
c.Description, mergepatch.ToYAMLOrError(c.Original), mergepatch.ToYAMLOrError(c.Sorted), jsonToYAMLOrError(original))
c.Description, mergepatch.ToYAMLOrError(c.Original), mergepatch.ToYAMLOrError(c.Sorted), jsonToYAMLOrError(got))
}
}
}
Expand Down Expand Up @@ -2068,10 +2068,10 @@ func twoWayTestCaseToJSONOrFail(t *testing.T, c StrategicMergePatchTestCase) ([]
if expectedResult == nil {
expectedResult = c.Modified
}
return testObjectToJSONOrFail(t, c.Original, c.Description),
testObjectToJSONOrFail(t, c.TwoWay, c.Description),
testObjectToJSONOrFail(t, c.Modified, c.Description),
testObjectToJSONOrFail(t, expectedResult, c.Description)
return sortJsonOrFail(t, testObjectToJSONOrFail(t, c.Original), c.Description),
sortJsonOrFail(t, testObjectToJSONOrFail(t, c.TwoWay), c.Description),
sortJsonOrFail(t, testObjectToJSONOrFail(t, c.Modified), c.Description),
sortJsonOrFail(t, testObjectToJSONOrFail(t, expectedResult), c.Description)
}

func twoWayRawTestCaseToJSONOrFail(t *testing.T, c StrategicMergePatchRawTestCase) ([]byte, []byte, []byte, []byte) {
Expand Down Expand Up @@ -2168,11 +2168,11 @@ func testThreeWayPatchForRawTestCase(t *testing.T, c StrategicMergePatchRawTestC
}

func threeWayTestCaseToJSONOrFail(t *testing.T, c StrategicMergePatchTestCase) ([]byte, []byte, []byte, []byte, []byte) {
return testObjectToJSONOrFail(t, c.Original, c.Description),
testObjectToJSONOrFail(t, c.Modified, c.Description),
testObjectToJSONOrFail(t, c.Current, c.Description),
testObjectToJSONOrFail(t, c.ThreeWay, c.Description),
testObjectToJSONOrFail(t, c.Result, c.Description)
return sortJsonOrFail(t, testObjectToJSONOrFail(t, c.Original), c.Description),
sortJsonOrFail(t, testObjectToJSONOrFail(t, c.Modified), c.Description),
sortJsonOrFail(t, testObjectToJSONOrFail(t, c.Current), c.Description),
sortJsonOrFail(t, testObjectToJSONOrFail(t, c.ThreeWay), c.Description),
sortJsonOrFail(t, testObjectToJSONOrFail(t, c.Result), c.Description)
}

func threeWayRawTestCaseToJSONOrFail(t *testing.T, c StrategicMergePatchRawTestCase) ([]byte, []byte, []byte, []byte, []byte) {
Expand Down Expand Up @@ -2222,7 +2222,7 @@ func testPatchApplication(t *testing.T, original, patch, expected []byte, descri
}
}

func testObjectToJSONOrFail(t *testing.T, o map[string]interface{}, description string) []byte {
func testObjectToJSONOrFail(t *testing.T, o map[string]interface{}) []byte {
if o == nil {
return nil
}
Expand All @@ -2231,7 +2231,13 @@ func testObjectToJSONOrFail(t *testing.T, o map[string]interface{}, description
if err != nil {
t.Error(err)
}
return j
}

func sortJsonOrFail(t *testing.T, j []byte, description string) []byte {
if j == nil {
return nil
}
r, err := sortMergeListsByName(j, mergeItem)
if err != nil {
t.Errorf("error: %s\nin test case: %s\ncannot sort object:\n%s\n", err, description, j)
Expand Down