pushtest

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package pushtest provides a scripted push.Pusher and an in-process APNs server so push behaviour is testable without Apple.

Why

The interesting push paths are the failures: a 410 that must invalidate a token, a 429 that must back off, a certificate that expired, a burst that must coalesce. None of them can be provoked against the real APNs from a unit test. Fake records every push and returns scripted results for the service and notifier tests; Server is a TLS HTTP/2 endpoint that answers by token according to a Script, with 200 for anything unscripted, so appleplatformservices/push/apns and the end-to-end suite exercise the real client against Apple's documented status codes (decision record 0007).

The package asserts nothing itself and holds no production code.

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