streamstest

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package streamstest is a fake AudD stream API for tests: stream management methods, longpoll, and the recent-results endpoint.

Index

Constants

View Source
const Token = "0123456789abcdef0123456789abcdef"

Token is the placeholder API token the fake accepts.

Variables

This section is empty.

Functions

func Category

func Category(radioID int) string

Category is the longpoll category for a radio ID under Token.

func RecentBody

func RecentBody(capacity int, songs ...map[string]any) json.RawMessage

RecentBody builds a getChannelById response holding songs as a ring buffer of the given capacity, the way AudD returns it: Elements[(oldest+i) % capacity] runs from the oldest to the newest, unused slots are null.

Types

type Call

type Call struct {
	Method string // AudD method ("getStreams", "longpoll", "getChannelById", ...)
	Params url.Values
}

Call is one request the fake received.

type Server

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

Server is a fake api.audd.io.

func New

func New(t testing.TB) *Server

New starts a fake server. Longpoll requests wait at most lpTimeout (instead of the requested timeout) before answering with a keepalive.

func (*Server) CallbackURL

func (s *Server) CallbackURL() string

CallbackURL returns the account's callback URL.

func (*Server) Calls

func (s *Server) Calls() []Call

Calls returns the requests received so far.

func (*Server) Client

func (s *Server) Client() *audd.Client

Client returns an audd-go client wired to the fake, without retries.

func (*Server) ClientWithToken

func (s *Server) ClientWithToken(tok string) *audd.Client

ClientWithToken is Client with another API token.

func (*Server) Count

func (s *Server) Count(method string) int

Count returns how many requests used an AudD method.

func (*Server) FailNextPolls

func (s *Server) FailNextPolls(n int)

FailNextPolls makes the next n longpoll requests return HTTP 500.

func (*Server) FailNextRecent

func (s *Server) FailNextRecent(n int)

FailNextRecent makes the next n recent-results requests return HTTP 500.

func (*Server) HTTPClient

func (s *Server) HTTPClient() *http.Client

HTTPClient returns a client that sends every request (whatever its host) to the fake.

func (*Server) Push

func (s *Server) Push(radioID int, body json.RawMessage)

Push queues a raw longpoll body for a stream.

func (*Server) PushMatch

func (s *Server) PushMatch(radioID int, timestamp, artist, title string, playLength int)

PushMatch queues a recognition for a stream's longpoll.

func (*Server) PushMatchFor

func (s *Server) PushMatchFor(tok string, radioID int, timestamp, artist, title string, playLength int)

PushMatchFor queues a recognition for a stream's longpoll category under another API token.

func (*Server) PushNotification

func (s *Server) PushNotification(radioID, code int, message string, running bool, at int64)

PushNotification queues a stream notification for a stream's longpoll.

func (*Server) SetNoCallbackURL

func (s *Server) SetNoCallbackURL()

SetNoCallbackURL makes getCallbackUrl answer with error 19.

func (*Server) SetRecent

func (s *Server) SetRecent(radioID int, body json.RawMessage)

SetRecent sets the getChannelById response for a stream.

func (*Server) SetStreams

func (s *Server) SetStreams(streams ...Stream)

SetStreams replaces the account's streams.

func (*Server) SetToken

func (s *Server) SetToken(tok string)

SetToken changes the API token the fake accepts (as after a rotation).

func (*Server) Streams

func (s *Server) Streams() []Stream

Streams returns the account's streams.

type Stream

type Stream struct {
	RadioID int    `json:"radio_id"`
	URL     string `json:"url"`
	Running bool   `json:"stream_running"`
}

Stream is a stream the fake account has.

Jump to

Keyboard shortcuts

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