mock

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 5 Imported by: 0

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL