conformance

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package conformance is the sensor protocol conformance suite (RFC-026 WP-S3, RFC-023 D23), starting with results ingest.

It has two halves:

  • FakePlatform, a control plane that implements the v2 results contract (RFC-026 §3) strictly and the v1 routes a sensor uses, records every request and can be told to fail in each §3.8 class. The SDK's own tests run against it: they check the SDK sends the right headers and digest, retries only what it should, splits on 413, never resends a partially accepted report and reuses report_id on retry.
  • The live suite (live_test.go), which runs the same contract against a real API: OPENCTEM_CONFORMANCE_URL and OPENCTEM_CONFORMANCE_KEY (a sensor key) select it; see the package README in the test file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakePlatform

type FakePlatform struct {
	Server *httptest.Server
	// APIKey is the sensor key it accepts.
	APIKey string
	// V2 serves the v2 routes and advertises them; false behaves like a
	// platform from before RFC-026 (404 on /api/v2).
	V2 bool
	// Limits are published on hello.
	Limits protov2.Limits
	// Tools are the sensor's declared tools (empty: any).
	Tools []string
	// contains filtered or unexported fields
}

FakePlatform is an in-process control plane. Safe for concurrent use.

func NewFakePlatform

func NewFakePlatform(v2 bool) *FakePlatform

NewFakePlatform starts a fake platform. Close it with Close.

func (*FakePlatform) AcceptedFindings

func (f *FakePlatform) AcceptedFindings() int

AcceptedFindings counts the findings of committed v2 reports plus v1 reports.

func (*FakePlatform) Close

func (f *FakePlatform) Close()

Close stops the server.

func (*FakePlatform) CommandState

func (f *FakePlatform) CommandState(id string) (string, string)

CommandState returns a command's state and its error message.

func (*FakePlatform) HeartbeatOutbox

func (f *FakePlatform) HeartbeatOutbox() []json.RawMessage

HeartbeatOutbox returns the outbox objects heartbeats carried.

func (*FakePlatform) OpenCommand

func (f *FakePlatform) OpenCommand(id string)

OpenCommand registers a running command assigned to the sensor.

func (*FakePlatform) Reports

func (f *FakePlatform) Reports() map[string]*StoredReport

Reports returns the accepted v2 reports by id.

func (*FakePlatform) Requests

func (f *FakePlatform) Requests() []Request

Requests returns the recorded requests.

func (*FakePlatform) RequestsTo

func (f *FakePlatform) RequestsTo(method, prefix string) []Request

RequestsTo returns the recorded requests whose path has prefix.

func (*FakePlatform) SetAPIKey

func (f *FakePlatform) SetAPIKey(key string)

SetAPIKey replaces the accepted sensor key (a key rotation).

func (*FakePlatform) SetFault

func (f *FakePlatform) SetFault(fl Fault)

SetFault installs a fault injector (nil removes it).

func (*FakePlatform) SetV2

func (f *FakePlatform) SetV2(on bool)

SetV2 switches the v2 routes on or off.

func (*FakePlatform) URL

func (f *FakePlatform) URL() string

URL is the base URL.

func (*FakePlatform) V1Reports

func (f *FakePlatform) V1Reports() []*ctis.Report

V1Reports returns the reports received on the v1 ingest route.

type Fault

type Fault func(r *http.Request, seq int) *FaultAnswer

Fault makes the fake answer a request with an error instead of handling it. Return nil to handle it normally.

type FaultAnswer

type FaultAnswer struct {
	Status     int
	Problem    protov2.ProblemType // "" for a plain (non-problem) answer
	RetryAfter string
	// Drop closes the connection without answering (a network error, the
	// sender cannot tell whether the request was processed). With Process
	// the request is handled first: "the response was lost".
	Drop    bool
	Process bool
}

FaultAnswer is an injected answer.

type Request

type Request struct {
	Method, Path string
	Header       http.Header
	Body         []byte // as sent (compressed when Content-Encoding is set)
	Status       int    // what the fake answered
}

Request is one request the fake received.

type StoredReport

type StoredReport struct {
	ReportID  string
	CommandID string
	Segments  map[int]segment
	Committed bool
	Status    protov2.Status
}

StoredReport is a report the fake accepted.

Jump to

Keyboard shortcuts

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