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

[Feature Request]: MatchYAML #74

Open
pmarchini opened this issue Aug 7, 2023 · 5 comments
Open

[Feature Request]: MatchYAML #74

pmarchini opened this issue Aug 7, 2023 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@pmarchini
Copy link

🚀 Feature Proposal

Considering the existence of the MatchJSON function, I suggest to introduce a similar implementation for YAML files: MatchYAML.

If agreeable, I would like to collaborate implementing this feature.

Motivation

I'm using this library for a project where I need to handle some data via JSON and YAML and I'd like to have the same functionality that I've with MatchJSON

Example

No response

@pmarchini pmarchini added the enhancement New feature or request label Aug 7, 2023
@gkampitakis
Copy link
Owner

Hey 👋 Thanks for opening this issue and using go-snaps. I have thought about it but wasn't sure if it's a functionality people would use.

If agreeable, I would like to collaborate implementing this feature.

Not sure if you had any look on the MatchJSON and how is implemented. Under the hood it's using gjson and sjson for accessing values and assinging values into keys. Unfortunately yaml doesn't have some similar support so we should built something similarto support this functionality ( e.g. get a specific key and set a specific key ).

That said happy to discuss about it.

@gkampitakis gkampitakis added the help wanted Extra attention is needed label Jan 21, 2024
@markussiebert
Copy link

Hey 👋 do you think It would be possible to add an option, to just render the snapshot as yaml? That would be handy!

@gkampitakis
Copy link
Owner

You mean save it as yaml on the snap file? There is this option now where you can do

snaps.WithConfig(snaps.Ext(".yaml")). MatchStandaloneSnapshot(t, <yaml string>)

This will create a file <name>.snap.yaml with your contents. Or you had something else in mind?

@markussiebert
Copy link

markussiebert commented Oct 10, 2024

Ok, now the file has the ending .yaml, but is not a valid yaml file...

What I am Looking for is something like this

rspYml, rspYmlErr := yaml.Marshal(rsp)
s.MatchSnapshot(t, string(rspYml), rspYmlErr)

this is working :-) but one line would be nice... but really - as I now have something working, it's not urgent :-)

Really like your snaps library!

@gkampitakis
Copy link
Owner

Okay I see your point. Yes that would be something that I would like to built inside the MatchYAML potentially similar to what MatchJSON does https://github.com/gkampitakis/go-snaps/blob/main/snaps/matchJSON.go#L143-L160.

I can introduce the MatchYAML method that will do that, but won't do anything else apart from that, meaning no matchers support as in JSON.

As per my previous comment

Not sure if you had any look on the MatchJSON and how is implemented. Under the hood it's using gjson and sjson for accessing values and assinging values into keys. Unfortunately yaml doesn't have some similar support so we should built something similarto support this functionality ( e.g. get a specific key and set a specific key ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants