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

Diffs on structs with nested time.Time objects produce hard to read diffs #1078

Open
shawc71 opened this issue May 22, 2021 · 1 comment
Open

Comments

@shawc71
Copy link

shawc71 commented May 22, 2021

We recently observed tough to read diffs produced by testify on assertion failures on structs when the structs contain nested time.Time objects.

I have created this repo with this testfile that does a minimal repro of the issue https://github.com/shawc71/testify-issue-demo/blob/master/example_test.go, this uses the latest testify commit on master.

In summary, given a struct like:

type structWithTime struct {
        	someTime   *time.Time
        	someString string
}

the following produces a diff that is 1220 lines+ and unparsable for humans:

	t.Run("different tzs", func(t *testing.T) {
		expectedTime, err := time.Parse("2006-01-02", "2020-05-22")
		assert.NoError(t, err)
		expected := &structWithTime{
			someTime:   &expectedTime,
			someString: "some val",
		}

		loc, err := time.LoadLocation("America/New_York")
		assert.NoError(t, err)
		actualTime, err := time.ParseInLocation("2006-01-02", "2020-05-21", loc)
		actual := &structWithTime{
			someTime:   &actualTime,
			someString: "some val",
		}
		assert.Equal(t, expected, actual)
	})

I believe this was an unintended side-effect of #895.

This makes doing assertions on structs with time.Time pretty rough. I imagine having a time.Time in a struct and being able to do assertions on those structs is a pretty common use case so I think we should make this nicer. :)

I am working on a PR to address this :)

@shawc71 shawc71 changed the title Diffs on time.Time objects nested inside structs produce hard to read diffs Diffs on structs with nested time.Time objects produce hard to read diffs May 22, 2021
@shawc71
Copy link
Author

shawc71 commented May 22, 2021

Here's my attempt at fixing it: #1079

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant