Documentation ¶
Overview ¶
Package test provides utilities for running integration tests on the trace agent. You may use the runner to start a fake backend, a trace-agent instance with a custom configuration, post payloads to the agent and assert the results.
To use this package, start by instantiating a runner. It needs not be initialized and can be used as is, for example:
// this runner is ready to use: var runner test.Runner
Next, start the fake backend before running any tests:
if err := runner.Start(); err != nil { log.Fatal(err) }
Then, use `runner.RunAgent`, `runner.Post`, `runner.Out` and `runner.KillAgent` to run tests. For a full demonstration, see the package example.
Example ¶
The below example shows a common use-case scenario for the runner.
var runner Runner // Start the runner. if err := runner.Start(); err != nil { log.Fatal(err) } defer log.Fatal(runner.Shutdown(time.Second)) // Run an agent with a given config. conf, err := ioutil.ReadFile("/opt/datadog-agent/etc/datadog.yaml") if err != nil { log.Fatal(err) } if err := runner.RunAgent(conf); err != nil { log.Fatal(err) } // Post a payload. payload := pb.Traces{ pb.Trace{testutil.RandomSpan()}, pb.Trace{testutil.RandomSpan()}, } if err := runner.Post(payload); err != nil { log.Fatal(err) } // Assert the results. switch v := (<-runner.Out()).(type) { case pb.TracePayload: fmt.Println("OK traces: ", len(v.Traces)) case stats.Payload: fmt.Println("OK stats: ", len(v.Stats)) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotInstalled = errors.New("agent: trace-agent not found in $PATH")
ErrNotInstalled is returned when the trace-agent can not be found in $PATH.
var ErrNotStarted = errors.New("runner: not started")
ErrNotStarted is returned when attempting to operate an unstarted Runner.
Functions ¶
This section is empty.
Types ¶
type Runner ¶
type Runner struct { // Verbose will make the runner output more verbose, more specifically // around operations regarding the trace-agent process. Verbose bool // ChannelSize specifies the size of the payload buffer of the fake backend. // If reached, HTTP handlers will block until payloads are received from // the out channel. It defaults to 100. ChannelSize int // contains filtered or unexported fields }
Runner can start an agent instance using a custom configuration, send payloads to it and act as a fake backend. Call Start first to initiate the fake backend, then RunAgent to start agent instances. Post may be used to send payloads to the agent and Out to receive its output.
func (*Runner) KillAgent ¶
func (s *Runner) KillAgent()
KillAgent kills any agent that was started by this runner.
func (*Runner) Out ¶
func (s *Runner) Out() <-chan interface{}
Out returns a channel which will provide payloads received by the fake backend. They can be of type pb.TracePayload or agent.StatsPayload.
func (*Runner) Post ¶
Post posts the given list of traces to the trace agent. Before posting, agent must be started. You can start an agent using RunAgent.