elastictest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package elastictest is a fake Elasticsearch 8 / OpenSearch 2 for the tests of the packages that open an Elasticsearch source (the session, the engine through it): an http.Handler over in-memory documents that answers the requests locklog sends (the root, the privilege checks, _resolve/index, _field_caps, _mapping, _settings, _count and _search with bool filters, sort, search_after and the two aggregation kinds), behind basic or API-key authentication unless Open.

The elastic package's own tests have a richer fake of their own; this one only needs to be faithful to the subset a session reads.

Index

Constants

View Source
const ReadOnlyGrants = `` /* 175-byte string literal not displayed */

ReadOnlyGrants is the _privileges answer of a read-only role on logs-* (shape recorded from Elasticsearch 8.15).

View Source
const WriteGrants = `` /* 183-byte string literal not displayed */

WriteGrants holds a write privilege on the source's indices.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doc

type Doc struct {
	Index  string
	ID     string
	TS     time.Time
	Fields map[string]any
}

Doc is one document: its index, id, time, and flat keyword fields (and the message), each a string or a []string.

type Server

type Server struct {
	// Pattern is the index segment the source names (default "logs-*").
	Pattern string
	// Indices are the concrete indices the pattern resolves to (default
	// logs-a, logs-b).
	Indices []string
	Docs    []Doc
	// OpenSearch answers as OpenSearch 2 (authinfo, no _privileges).
	OpenSearch bool
	// Grants is the Elasticsearch _privileges answer (default
	// ReadOnlyGrants); Roles the OpenSearch roles of the user.
	Grants string
	Roles  []string
	// Types are the mapped fields and their types (default: @timestamp
	// date, message text, every other field of a document keyword).
	Types map[string]string
	// User and Password, or APIKey (the encoded key), authenticate a
	// request; Open serves every request without credentials.
	User, Password, APIKey string
	Open                   bool
	// contains filtered or unexported fields
}

Server is the fake. Set its fields before serving.

func (*Server) Requests

func (f *Server) Requests() []string

Requests returns the method and path of every request served.

func (*Server) ServeHTTP

func (f *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

Jump to

Keyboard shortcuts

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