Skip to content
This repository was archived by the owner on May 29, 2018. It is now read-only.
This repository was archived by the owner on May 29, 2018. It is now read-only.

MockPostsService setup #2

@ezbercih

Description

@ezbercih

Could you elaborate on the design of the MockPostsService in posts.go and decisions around how it is setup? To be more specific:

  • Why do we need the following line?
    var _ PostsService = &MockPostsService{}
  • Is it a common practice to create a shell type whose functions (that closely mimic the interface) can be swapped depending on the test and interface methods call them? Why not create separate mock types that implement the interface for different tests?
  • Lastly, what is the guidance around returning a slice of object pointers ([]*Post) vs. a slice of objects ([]Post)? Is there a significant benefit?

I see you got inspired quite a bit from https://github.com/google/go-github when designing the client and options interface ideas, with a departure from implementing services as interfaces with types that implement them instead of directly creating them as types. I am going back and forth on this on my implementation but leaning towards the interface approach for better testing.

And I just wanted to say this is an awesome project for hashing out best practices. I really appreciate the effort you guys put in it, as I am working on an SDK for a set of REST APIs and it helps to validate some of the decisions I made.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions