vagrant

package module
v0.0.0-...-62ba563 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 11 Imported by: 0

README

This library helps you to programmatically pilot vagrant using Go.

It provides an easy API around the vagrant command line tool.

Getting Started

There is a test written inside vagrant_test.go that helps you to figure out what this library provides. A few hints:

  • machine, err := vagrant.Up(ctx) helps you to provision a new virtual machine.
  • machine.Destroy(ctx) helps you to cleanup after yourself.
  • machine.Exec(ctx, "touch", "/tmp/file.text") execute a command inside the virtual machine via ssh.

Run tests

This library does not replace the testing package. It just provide a few function that you can use to leverage vagrant as part of your testing environment.

You can run the test I wrote but you need a functional vagrant installation in your laptop:

$ git clone git@github.com:gianarb/vagrant-go
$ cd vagrant-go
$ go test --timeout 30m -v ./...

Timeout is optional but it depends on how fast you can download the Ubuntu image from the internet.

NOTE: Parallelization is not supported.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Vagrant

type Vagrant struct {
	VagrantBinPath string
	Name           string
	Workdir        string

	Stdout io.ReadWriter
	Stderr io.ReadWriter
	// contains filtered or unexported fields
}

func Up

func Up(ctx context.Context, opts ...VagrantOpt) (*Vagrant, error)

func (*Vagrant) Destroy

func (v *Vagrant) Destroy(ctx context.Context) error

func (*Vagrant) Exec

func (v *Vagrant) Exec(ctx context.Context, args ...string) ([]byte, error)

type VagrantOpt

type VagrantOpt func(*Vagrant)

func RunAsync

func RunAsync() VagrantOpt

func WithLogger

func WithLogger(log func(string, ...interface{})) VagrantOpt

func WithMachineName

func WithMachineName(name string) VagrantOpt

func WithStderr

func WithStderr(s io.ReadWriter) VagrantOpt

func WithStdout

func WithStdout(s io.ReadWriter) VagrantOpt

func WithVagrantBinPath

func WithVagrantBinPath(path string) VagrantOpt

func WithWorkdir

func WithWorkdir(workdir string) VagrantOpt

Jump to

Keyboard shortcuts

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