testarango

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: BSD-2-Clause Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testarango is a golang library to write unit tests for arangodb based packages and applications. The library allows to use existing arangodb instance to create a isolated and disposable database and users to run unit tests. The disposable database and users are also cleaned up at the end of the test cycle.

Prerequisites

  • An existing and running instance of arangodb
  • An existing user with administrative rights to create any random database. The root user could also be used, however care must be taken.

Usage

A testable instance of arangodb can be obtained in two way,
either by using env variables or directly supplying the
credentials.

* Env variables: Set the following ones
   ARANGO_HOST
   ARANGO_USER
   ARANGO_PASS
   ARANGO_PORT is optional, by default it uses 8529

	ta,err := NewTestArangoFromEnv(true)

* Supply them directly

	ta,err := NewTestArango(user,pass,host,port,true)

Quick Start

		package quickstart

		import (
			"github.com/dictyBase/arangomanager/testarango"
			"testing"
			"log"
			"os"
		)

		var ta *testarango.TestArango

		func TestMain(m *testing.M) {
			ta, err = testarango.NewTestArangoFromEnv(true)
			if err != nil {
				log.Fatal(err)
			}
			code := m.Run()
			// clean up the database at the end
			dbh.Drop()
			os.Exit(code)
		}

		func TestAlmighty(t *testing.T) {
			// connect to disposable test instatnce
			instance, err := ConnectSomeHow(
				ta.User,
				ta.Pass,
				ta.Host,
				ta.Port,
				ta.Database,
				ta.IsTls,
			)
			// run tests here
			.......
		}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckArangoEnv

func CheckArangoEnv() error

CheckArangoEnv checks for the presence of the following environment variables

ARANGO_HOST
ARANGO_USER
ARANGO_PASS

Types

type TestArango

type TestArango struct {
	*arangomanager.ConnectParams
	*arangomanager.Session
}

TestArango is a container for managing a disposable database instance.

func NewTestArango

func NewTestArango(
	user, pass, host string,
	port int,
	isCreate bool,
) (*TestArango, error)

NewTestArango is a constructor for TestArango instance from the given database credentials. isCreate toggles whether a random disposable test database will be created during instantiation. It is false by default.

func NewTestArangoFromEnv

func NewTestArangoFromEnv(isCreate bool) (*TestArango, error)

NewTestArangoFromEnv is a constructor for TestArango instance. It expects the following environmental variables to be set.

ARANGO_HOST
ARANGO_USER
ARANGO_PASS
ARANGO_PORT is optional, by default it uses 8529

isCreate toggles whether a random disposable test database will be created during instantiation. It is false by default.

func (*TestArango) CreateTestDb

func (ta *TestArango) CreateTestDb(
	name string,
	opt *driver.CreateDatabaseOptions,
) error

CreateTestDb creates a test database of given name.

Jump to

Keyboard shortcuts

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