gkampitakis/go-snaps

[Bug]: mkdir /usr/local/go/src/runtime/__snapshots__: permission denied

Closed this issue ยท 2 comments

Description

Im my case I'm snapshotting HTTP requests in a stub server in order to check the calls I'm making are correctly formatted (headers, body etc.). I have this running as part of a integration test. The call to snaps.MatchJSON is made in the HTTP handler of the stub server.

It appears the algorithm that searches for the test folder skips over it (see screenshot). I can see it iterating the test method but the algorithm doesn't successfully return it.

Steps to Reproduce

Use snaps.MatchJSON outside the actual test function, for example in a stub server handler which the code is making HTTP requests to. Run the test and see the test fail when trying to create the snapshots folder.

go-snaps

Expected Behavior

Test should resolve the test method folder

Hey ๐Ÿ‘‹ thanks for opening this issue.

I don't believe this is a bug but more of a known limitation, but I am not sure how exactly your setup looks. If you can share a reproducible example happy to look if this is an edge case I missed.

There is a workaround for this though if you are interested to use. It's using an absoulute path where you override the baseCallermethod entitrely.

t.Run("should allow absolute path", func(t *testing.T) {
			_, b, _, _ := runtime.Caller(0)
			basepath := filepath.Dir(b)

			snaps.WithConfig(snaps.Dir(basepath+"/absolute_path"), snaps.Filename("my_test")).
				MatchSnapshot(t, "supporting absolute path")
		})

Also there might be a similar use case a user had and was adressed with the above if you want to read #60 (comment)

@jackmatt2 closing this one as I see the ๐Ÿ‘ . If you have more issues please either comment here or create a new issue, happy to help ๐Ÿ˜„