optimizely / optimizely/go-sdk
[ENHANCEMENT] Make it easier to test from the outside?
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 18
- Forks
- 16
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 1
Description
Description
This library is difficult to test because instead of returning pointers to structs, the sdk returns structs as values forcing the consumer to cast it to a pointer in order to call the necessary methods on the receiver (as the receiver is a pointer). The difficulty comes in when one wants to mock these calls out for testing purpose in their own application as a value struct can not be cast to an interface, only pointers. I wonder if its possible to add additional constructor methods that return the pointer. Thoughts?
Benefits
Easier testability from the consumers perscpective.
Detail
No response
Examples
Example:
func (o *OptimizelyClient) CreateUserContextP(userID string, attributes map[string]interface{}) *OptimizelyUserContext {
return newOptimizelyUserContextP(o, userID, attributes, nil)
}
Risks/Downsides
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the exported constructors and value-returning SDK methods, including OptimizelyClient.CreateUserContextP and newOptimizelyUserContextP. Determine the scope of pointer-returning alternatives and how consumers would use them for interface-based mocks; done should include an agreed API design and coverage of the affected constructors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100