testd

package module
v0.0.0-...-6dcf56f Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2015 License: Apache-2.0 Imports: 6 Imported by: 0

README

testd

It is a library that makes easier to write blackbox tests on daemons/services.

If you are thinking about unit tests, this library will not help you with that. They are a good idea on a lot of cases, and it is not on scope of this document to argue about when it is better to write integration/blackbox tests, instead of unit tests.

When you found yourself needing to write integration tests, then you will need some stuff:

  • A way to start services
  • A way to stop them
  • A way to get the logs from the services

Well, if you value deterministic tests, isolation will be your friend. One good way to get isolation is to start/stop a instance of the service on setup/teardown.

Another thing that is important is the logs, if a test fails, why it failed ? On integration tests this is a little harder to get only by the last performed change (it is actually one of the drawbacks of integration tests, in comparison with unit tests).

testd provides an easy way to do that, and just that :-).

What would be the logs ?

The logs are actually everything that the daemon sends to stdout and stderr. This fits well the same model used by docker, where services just send logs to stdout and the docker daemon (or some other daemon, like journald) captures it.

With testd you will be able to chose where to save the logs.

How to use it ?

Checkout the godocs documentation.

Documentation

Overview

testd that makes easier to write integration tests that depends on runnings daemons/services.

Create a Testd instance, informing where you want the logs to be saved, the command to execute and its arguments.

daemon, err := testd.New("./tests/debug/daemon.log", "daemon", "arg1", "arg2")

Do your testing, that depends on the daemon being running. When you are done testing, just call the Stop method.

err := daemon.Stop()

Remember to do proper error handling, both on New and Stop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Testd

type Testd struct {
	// contains filtered or unexported fields
}

func New

func New(logFilePath string, name string, arg ...string) (*Testd, error)

New creates a new testd instance. It will call exec.Command using the given name and arg and start the daemon. All logs (stdout and stderr) of the daemon will be saved at the given logFilePath. If a directory on logFilePath does not exist, it will attempt to create the directory for you. You must always call Testd.Stop, even when you know that the daemon already exited for some reason.

func (*Testd) Stop

func (self *Testd) Stop() error

Stops the daemon, if it is not already not stopped

Jump to

Keyboard shortcuts

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