Documentation
¶
Overview ¶
Package mock provides a test Open Ranking server backed by net/http/httptest. It is intended for use in tests, both to test this SDK's own client and to let external consumers test code that calls an Open Ranking provider.
Usage:
caps := openranking.CapabilityDoc{
RankPubkeys: []openranking.Algorithm{{ID: "algo-v1"}},
StatsPubkey: []openranking.Algorithm{{ID: "algo-v1"}},
}
server := mock.NewServer(caps)
defer server.Close()
server.OnRankPubkeys = func(r openranking.RankPubkeysRequest) (openranking.RankPubkeysResponse, error) {
return openranking.RankPubkeysResponse{Results: []openranking.RankedPubkey{{Pubkey: r.Pubkeys[0], Rank: 1}}}, nil
}
client, err := openranking.NewClient(server.URL, server.Client())
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Server ¶
type Server struct {
*httptest.Server
OnStatsPubkey func(openranking.StatsPubkeyRequest) (openranking.StatsPubkeyResponse, error)
OnRankPubkeys func(openranking.RankPubkeysRequest) (openranking.RankPubkeysResponse, error)
OnRecommendPubkeys func(openranking.RecommendPubkeysRequest) (openranking.RecommendPubkeysResponse, error)
OnSearchPubkeys func(openranking.SearchPubkeysRequest) (openranking.SearchPubkeysResponse, error)
OnFollowers func(openranking.FollowersRequest) (openranking.FollowersResponse, error)
OnMuters func(openranking.MutersRequest) (openranking.MutersResponse, error)
OnCompromisedPubkeys func(openranking.CompromisedPubkeysRequest) (openranking.CompromisedPubkeysResponse, error)
}
Server is a test Open Ranking server. Set the On* fields before (or during) requests. Endpoints with a nil handler return 501 Not Implemented.
func NewServer ¶
func NewServer(caps openranking.CapabilityDoc) *Server
NewServer starts a test HTTP server that serves caps at openranking.EndpointCapabilities.
Click to show internal directories.
Click to hide internal directories.