Skip to content

autofixing assert.Equal -> assert.JSONEq can break working tests #274

@IvanMajeru-RecoLabs

Description

@IvanMajeru-RecoLabs

Running the autofix via golangci-lint will convert this code:

func TestInvalidJSON(t *testing.T) {
	invalidJSON := []byte(`{invalid json`)
	results, err := Explode(&http.Request{}, invalidJSON)
	require.NoError(t, err, "should not return error for invalid JSON, just return original")
	require.Len(t, results, 1, "should return original bytes when JSON is invalid")
	assert.Equal(t, string(invalidJSON), string(results[0]), "should return original bytes unchanged")
}

to

func TestInvalidJSON(t *testing.T) {
	invalidJSON := []byte(`{invalid json`)
	results, err := Explode(&http.Request{}, invalidJSON)
	require.NoError(t, err, "should not return error for invalid JSON, just return original")
	require.Len(t, results, 1, "should return original bytes when JSON is invalid")
	assert.JSONEq(t, string(invalidJSON), string(results[0]), "should return original bytes unchanged")
}

but because the json is invalid we get an fail

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions