pushtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package pushtest provides a scripted push.Pusher and an in-process APNs server.

Design

Fake records targets and returns configured results for service and notifier tests. Server exposes a TLS HTTP/2 endpoint with per-token scripts and a default successful response. Tests can exercise invalid tokens, rate limits, request rejections and transport behavior without contacting APNs. These helpers do not establish live-device delivery.

References

Index

Constants

This section is empty.

Variables

View Source
var ErrScripted = errors.New("pushtest: scripted failure")

ErrScripted is a convenience error for Fake results.

Functions

func ClientCertStore

func ClientCertStore(topic string, cert tls.Certificate) push.StaticCertStore

ClientCertStore returns a push.CertStore whose certificate the Server trusts for mutual TLS, plus an option-compatible HTTP client factory.

Types

type Fake

type Fake struct {

	// Results by enrollment id; targets not listed are reported as Sent.
	Results map[mdm.EnrollmentID]push.Result
	// Err, when set, fails the whole batch.
	Err   error
	Calls [][]push.Target
	// contains filtered or unexported fields
}

Fake records pushes and returns scripted results.

func (*Fake) Push

func (f *Fake) Push(_ context.Context, targets []push.Target) (map[mdm.EnrollmentID]push.Result, error)

Push implements push.Pusher.

func (*Fake) Pushed

func (f *Fake) Pushed() []push.Target

Pushed returns every target pushed so far.

type Request

type Request struct {
	Token    string
	Topic    string
	PushType string
	Priority string
	Magic    string
	Headers  http.Header
}

Request is one notification the Server received.

type Script

type Script struct {
	Status     int
	Reason     string
	RetryAfter int
}

Script tells the Server how to answer a token.

type Server

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

Server is an in-process APNs endpoint. Tokens without a script get 200.

func NewServer

func NewServer() *Server

NewServer starts a TLS server. Use ClientCertificate to require mutual TLS.

func (*Server) Requests

func (s *Server) Requests() []Request

Requests returns the notifications received so far.

func (*Server) ScriptToken

func (s *Server) ScriptToken(token []byte, sc Script)

ScriptToken sets the response for a device token (hex).

Jump to

Keyboard shortcuts

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