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

Implement YAML support for imposters #72

Merged

Conversation

CodingNagger
Copy link

Hello, I implemented YAML support for imposters based on #21.

Copy link
Member

@joanlopez joanlopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks quite good, great job 👍

I left few comments. Ping me once you're done.

Thanks!!!


const (
jsonImposterExtension = ".imp.json"
yamlImposterExtension = ".imp.yml"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to YAML's official FAQs, the official extension is .yaml.

However, I know .yml is also widely used.

So, I'd suggest you to add support for both file extensions.

if err != nil {
log.Printf("error trying to load %s imposter: %v", f, err)
log.Printf("error trying to load %v imposter: %v", config, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep the file path here, as it's easier to see which imposter is failing.

s.addImposterHandler(imposters, f)
log.Printf("imposter %s loaded\n", f)
s.addImposterHandler(imposters, config)
log.Printf("imposter %v loaded\n", config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for the file path.

@@ -134,9 +135,9 @@ func (s *Server) Shutdown() error {
return nil
}

func (s *Server) addImposterHandler(imposters []Imposter, imposterFilePath string) {
func (s Server) addImposterHandler(imposters []Imposter, config ImposterConfig) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I'd use imposterConfig as the variable name, instead. The same way you did for unmarshalImposters method.


var parseError error

switch imposterConfig.Type {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be defensive here and I'd add a default clause here with a proper error. Otherwise, if something weird happens, we'll omit the error which is something not desired in terms of UX.

internal/server/http/server.go Outdated Show resolved Hide resolved
@@ -0,0 +1,7 @@
---
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, extend this example with all the valid attributes in order to ensure all of them works properly with YAML.

Co-authored-by: Joan López de la Franca Beltran <joanjan14@gmail.com>
@codecov-commenter
Copy link

Codecov Report

Merging #72 into master will increase coverage by 0.26%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #72      +/-   ##
==========================================
+ Coverage   92.85%   93.11%   +0.26%     
==========================================
  Files           8        8              
  Lines         238      247       +9     
==========================================
+ Hits          221      230       +9     
  Misses         13       13              
  Partials        4        4              
Impacted Files Coverage Δ
internal/server/http/imposter.go 83.33% <100.00%> (+5.55%) ⬆️
internal/server/http/server.go 88.15% <100.00%> (+1.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f64e409...2407e73. Read the comment docs.

@CodingNagger
Copy link
Author

ping @joanlopez

@aperezg aperezg linked an issue Oct 9, 2020 that may be closed by this pull request
@aperezg aperezg added this to the v0.4.1 milestone Oct 9, 2020
@aperezg aperezg changed the base branch from master to v0.4.1 October 9, 2020 20:14
@aperezg
Copy link
Member

aperezg commented Oct 9, 2020

@joanlopez ping! :P

Copy link
Member

@joanlopez joanlopez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice 👌 Thanks!!

PS: @aperezg feel free to merge it!

@aperezg aperezg merged commit 7e47d02 into friendsofgo:v0.4.1 Oct 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support YAML for configuration and imposters definition
4 participants