Defined lbryinc.Caller interface #63
Labels
No labels
area: devops
area: discovery
area: docs
area: livestream
area: proposal
consider soon
dependencies
Epic
good first issue
hacktoberfest
help wanted
icebox
level: 1
level: 2
level: 3
level: 4
needs: exploration
needs: grooming
needs: priority
needs: repro
needs: tech design
on hold
priority: blocker
priority: high
priority: low
priority: medium
resilience
Tom's Wishlist
type: bug
type: discussion
type: improvement
type: new feature
type: refactor
type: task
type: testing
unplanned
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: LBRYCommunity/lbry.go#63
Loading…
Reference in a new issue
No description provided.
Delete branch "feature/lbryinc_client_caller"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Defined lbryinc.Caller interface for easier drop-in replacement of lbryinc package in client code. This will help with testing and/or extending.
Note: I bumped minor version of the package because it introduces breaking changes in lbryinc package API.
@ -17,0 +18,4 @@
SetServerAddress(string)
GetServerAddress() string
UserMe() (ResponseData, error)
}
ResponseData
is a bad name. It should returnUserMeResponse
to conform to how we handle other clients with go. So that no fields of the response need to be parsed after the client has returned the response.@ -55,10 +55,17 @@ func launchDummyServer() {
log.Fatal(s.ListenAndServe())
}
func TestClient_Set_GetServerAddress(t *testing.T) {
should avoid underscores in go code method names.
@ -16,1 +16,3 @@
// Client stores data about internal-apis call it is about to make.
// Caller interface defines currently supported internal-apis methods.
type Caller interface {
SetServerAddress(string)
So when naming interfaces, those that end with an
er
should only have one method and it should be that remaining string. This is the convention for single method interfaces. So if you are naming an interfaceCaller
it should only specify one method and it should be calledCall
.@ -19,2 +25,3 @@
serverAddress string
AuthToken string
Logger *log.Logger
logger *log.Logger
What is the purpose of making these private and adding methods? There is no special logic in the getter/setter to require it.
Not blocking but definitely suggested.
@ -65,0 +75,4 @@
}
// GetServerAddress returns currently defined internal-apis server address.
func (c Client) GetServerAddress() string {
I specifically like this pattern. Does it allow for specially configured logging per type?
@ -19,2 +25,3 @@
serverAddress string
AuthToken string
Logger *log.Logger
logger *log.Logger
Can't define properties on an interface.
What's the purpose of having the Caller interface at all? Why not just have a straightforward api client?
@ -16,1 +16,3 @@
// Client stores data about internal-apis call it is about to make.
// Caller interface defines currently supported internal-apis methods.
type Caller interface {
SetServerAddress(string)
I did not know this
why are Call and doCall two separate functions? i would either make them one function, or rename doCall to better describe what it does
@ -16,1 +16,3 @@
// Client stores data about internal-apis call it is about to make.
// Caller interface defines currently supported internal-apis methods.
type Caller interface {
SetServerAddress(string)
https://golang.org/doc/effective_go.html#interface-names for reference
Shouldn't breaking changes cause a major version change?
semver.org
@lyoshenka
It makes it easier to provide a mock client in tests that satisfies Caller
interface
. Currently to test my code that is using a concrete client I have to launch a fake http server that is providing predefined responses, which I'm not a fan of.that's actually the recommended way to do it in go. there's even a package for it: https://golang.org/pkg/net/http/httptest/
here's a simple example: https://stackoverflow.com/a/51227660
@lyoshenka yeah, that's what I'm already using in my tests. Perhaps you're right and this complication is unwarranted here.
TIL about
httptest
Pull request closed