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

Single vs double spaced output #68

Open
mattharrigan opened this issue Jan 25, 2021 · 6 comments
Open

Single vs double spaced output #68

mattharrigan opened this issue Jan 25, 2021 · 6 comments

Comments

@mattharrigan
Copy link

I am getting inconsistent test failures. The difference is sometimes there are single spaces in the snapshot of a variable, and sometimes there are double spaces. Any ideas on why or how to fix? Thanks.

From go.sum

github.com/bradleyjkemp/cupaloy v2.3.0+incompatible h1:UafIjBvWQmS9i/xRg+CamMrnLTKNzo+bdmT/oH34c2Y=
github.com/bradleyjkemp/cupaloy v2.3.0+incompatible/go.mod h1:Au1Xw1sgaJ5iSFktEhYsS0dbQiS1B0/XMXl+42y9Ilk=
...
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@bradleyjkemp
Copy link
Owner

Hey @mattharrigan do you have an example of a test where you're seeing this inconsistency?
By double spaces are you meaning between the snapshots of variables or actually within the snapshot of a single variable?

Sorry for not replying sooner, the GitHub notification for this is showing as 6 hours ago 🤔

@cobbinma
Copy link

Hey @bradleyjkemp, I'm getting the same issue. The snapshot output for all tests seem to change from single / double spaces at random.

    --- FAIL: Test_Repository/get_opening_hours (0.00s)
        client_test.go:223: snapshot not equal:
            --- Previous
            +++ Current
            @@ -1,2 +1,2 @@
            -(*api.GetOpeningHoursSpecificationResponse)(specification:{dayOfWeek:2  opens:"11:00"  closes:"22:00"  validFrom:"3000-11-01T00:00:00Z"  validThrough:"3000-12-01T00:00:00Z"})
            +(*api.GetOpeningHoursSpecificationResponse)(specification:{dayOfWeek:2 opens:"11:00" closes:"22:00" validFrom:"3000-11-01T00:00:00Z" validThrough:"3000-12-01T00:00:00Z"})
{
	name: "get opening hours",
	test: func(t *testing.T) {
		ctx := context.Background()
		hours, err := repository.GetOpeningHoursSpecification(ctx, &api.GetOpeningHoursSpecificationRequest{
			VenueId: UUID,
			Date:    "3000-11-11T00:00:00Z",
		})
		require.NoError(t, err)

		cupaloy.SnapshotT(t, hours)
	},
},

@bradleyjkemp
Copy link
Owner

Ah are you using protobuf by any chance?

The default protobuf String() method intentionally introduces randomness: golang/protobuf#1269

Cupaloy shouldn't really be using the String() method by default but it'd be a breaking change to disable the behaviour. Cupaloy should probably have an option to disable this though.
An alternative is to marshal your protobuf message yourself before passing it to Cupaloy

@cobbinma
Copy link

thanks @bradleyjkemp 👍 , didn't know about that protobuf behaviour

@cobbinma
Copy link

cupaloy.New(cupaloy.UseStringerMethods(false)).SnapshotT(t, hours)

@bradleyjkemp
Copy link
Owner

Ah awesome there already is an option for disabling String() methods!

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

3 participants