-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: support configurable snapshot dir and filename #60
Conversation
77c84f1
to
282a669
Compare
snaps/snapshot.go
Outdated
callerPath := baseCaller(2) | ||
base := filepath.Base(callerPath) | ||
dir := filepath.Join(filepath.Dir(callerPath), c.snapsDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my use case I'd like to specify the directory in full, i.e. not to be influenced by the callerPath
. There are two cases I encountered for this, one is when ussing go-snaps in a goroutine, the base
is $GOROOT/src/runtime
; and the second when I'm using a testing framework that runs a single go test -- in my case godog, the base
is $GOPATH/pkg/mod/github.com/cucumber/godog@v0.12.6
.
I'd prefer if the given snapsDir
was used as is, perhaps if absolute path was given?
dir := filepath.Join(filepath.Dir(callerPath), c.snapsDir) | |
var dir string | |
if filepath.IsAbs(c.snapsDir) { | |
dir = c.snapsDir | |
} else { | |
dir = filepath.Join(filepath.Dir(callerPath), c.snapsDir) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey 👋 Thanks a lot for the feedback and using go-snaps
. The issue with the file at least for goroutines was fixed #44. I was able to verify this should not be an issue from v0.3.7
.
As for providing the directory in full I thought about it but I was a bit hesitant on how it would work with the Clean
. I like idea of the absolute and I ll play a bit with it as I can see people wanting to use it.
As for the godog unfortunately I am not really familiar with it. I would appreciate if you can share a snippet so I can potentially try and support it regardless of the snapsDir
configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, thanks for considering this!
I've created an example if I run go test example_test
this is what I get:
go test example_test.go
Feature: example feature
Scenario: example scenario # features/example.feature:3
Then expect snapshot "hello" # example_test.go:40 -> command-line-arguments.verifySnapshot
mkdir /home/zregvart/.asdf/installs/golang/1.19.5/packages/pkg/mod/github.com/cucumber/godog@v0.12.6/__snapshots__: permission denied
--- Failed steps:
Scenario: example scenario # features/example.feature:3
Then expect snapshot "hello" # features/example.feature:4
Error: mkdir /home/zregvart/.asdf/installs/golang/1.19.5/packages/pkg/mod/github.com/cucumber/godog@v0.12.6/__snapshots__: permission denied
1 scenarios (1 failed)
1 steps (1 failed)
217.55µs
--- FAIL: TestFeatures (0.00s)
--- FAIL: TestFeatures/example_scenario (0.00s)
suite.go:451: mkdir /home/zregvart/.asdf/installs/golang/1.19.5/packages/pkg/mod/github.com/cucumber/godog@v0.12.6/__snapshots__: permission denied
example_test.go:61: non-zero status returned, failed to run feature tests
FAIL
FAIL command-line-arguments 0.007s
FAIL
It seems to me supporting godog, and in general other similar testing frameworks that abstract away the testing framework might be a challenge -- so thank you for taking an interest and investing time into this.
For my use case, I've configured to use the version from this branch and I've resorted to using tricks to point to the directory where I want the snapshots to be created.
0abcdce
to
a0686d6
Compare
4b5e674
to
e7824fc
Compare
e7824fc
to
05183ab
Compare
) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/gkampitakis/go-snaps](https://togithub.com/gkampitakis/go-snaps) | require | patch | `v0.4.4` -> `v0.4.5` | --- ### Release Notes <details> <summary>gkampitakis/go-snaps</summary> ### [`v0.4.5`](https://togithub.com/gkampitakis/go-snaps/releases/tag/v0.4.5) [Compare Source](https://togithub.com/gkampitakis/go-snaps/compare/v0.4.4...v0.4.5) #### What's Changed - feat: support configurable snapshot dir and filename by [@​gkampitakis](https://togithub.com/gkampitakis) in [https://github.com/gkampitakis/go-snaps/pull/60](https://togithub.com/gkampitakis/go-snaps/pull/60) **Full Changelog**: gkampitakis/go-snaps@v0.4.4...v0.4.5 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/markussiebert/cdk-sops-secrets).
This pull request adds back support for allowing configurable snapshot filename and directory name. [ pr tha dropped config ]
Action Items:
Clean
functionalitycloses #58
Example usage of current api