apitester

package module
v0.0.0-...-f0b6623 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 13 Imported by: 0

README

APITester

APITester is a simple package for network testing against an API.

Build Status GoDoc Go Report Card Code Coverage

See Examples

Documentation

Index

Constants

View Source
const (
	DefaultProfileName = "profile0"
	AuthKey            = "authKey"
	RefreshTokenKey    = "refreshToken"
)

Variables

This section is empty.

Functions

func RandDataString

func RandDataString(name string) string

RandDataString returns a random data string from `name` set in dataStrings

func RandEmail

func RandEmail(username string, domainLength int) string

RandEmail returns a random email with the username and the length of the domain name provided Domain names and tlds are randomized

func RandInt

func RandInt(max int) int64

RandInt generates a random number where 0 <= n <= max

func RandLCLetters

func RandLCLetters(length int) string

RandLCLetters returns a random string of lower case letters from the English alphabet

func RandString

func RandString(length int) string

RandString returns a random string based on a set of runes

Types

type APITest

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

APITest tests your API

func NewAPITest

func NewAPITest(t *testing.T, baseURL string, logLevel LogLevel) *APITest

NewAPITest returns a new APITest instance

func (*APITest) CheckProfile

func (a *APITest) CheckProfile(profileName string)

CheckProfile checks a profile

func (*APITest) Decrement

func (a *APITest) Decrement(key string) int64

Decrement sets an integer in the number cache if it doesn't exist And then decrements it by 1 The resulting value is returned

func (*APITest) DestroyProfile

func (a *APITest) DestroyProfile(profileName string) (e error)

DestroyProfile destroys a profile - Cannot destroy the default profile - Cannot destroy the profile if it is the currently active profile

func (*APITest) Finish

func (a *APITest) Finish()

func (*APITest) GetInt

func (a *APITest) GetInt(name string) int64

GetInt gets the int value at `name` globally

func (*APITest) GetObject

func (a *APITest) GetObject(name string) interface{}

GetObject gets an object at `key` globally

func (*APITest) GetProfile

func (a *APITest) GetProfile(profileName string) (profile *UserProfile, e error)

GetProfile gets a profile by its name

func (*APITest) GetProfileNames

func (a *APITest) GetProfileNames() []string

GetProfileNames returns a list of profile names

func (*APITest) GetString

func (a *APITest) GetString(key string) string

GetString gets the string value identified by `name` from the global cache

func (*APITest) Increment

func (a *APITest) Increment(key string) int64

Increment sets an integer in the number cache if it doesn't exist And then decrements it by 1 The resulting value is returned

func (*APITest) NewProfile

func (a *APITest) NewProfile(name string) (userProfile *UserProfile, e error)

NewProfile creates a user profile indexed by `name`

func (*APITest) Note

func (a *APITest) Note(note string)

Note prints a string to log with an asterisk prefix

func (*APITest) Notef

func (a *APITest) Notef(note string, args ...interface{})

Notef call Note() with formatting

func (*APITest) ResetProfileToDefault

func (a *APITest) ResetProfileToDefault()

ResetProfileToDefault sets the activeProfile to the default profile

func (*APITest) SetActiveProfile

func (a *APITest) SetActiveProfile(profileName string)

SetActiveProfile sets the active profile

func (*APITest) SetInt

func (a *APITest) SetInt(name string, v int64) int64

SetInt sets an int value at `name` globally

func (*APITest) SetObject

func (a *APITest) SetObject(key string, obj interface{})

SetObject sets an object at `name` globally

func (*APITest) SetString

func (a *APITest) SetString(key, value string) string

SetString sets a string value at `key` globally

func (*APITest) Start

func (a *APITest) Start(title string)

Start starts a new story

type LogLevel

type LogLevel int

LogLevel specifies the log levels

const (
	// LogLevels
	LogLevelError LogLevel = 0
	LogLevelWarn  LogLevel = 1
	LogLevelInfo  LogLevel = 2
	LogLevelDebug LogLevel = 3
)

type Logger

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

func InitLogger

func InitLogger(logLevel LogLevel) *Logger

func (*Logger) Debug

func (l *Logger) Debug(message string)

func (*Logger) Error

func (l *Logger) Error(message string)

func (*Logger) Heading

func (l *Logger) Heading(message string)

func (*Logger) Indent

func (l *Logger) Indent()

func (*Logger) Info

func (l *Logger) Info(message string)

func (*Logger) Log

func (l *Logger) Log(message string)

Log writes a log message to stdout

func (*Logger) UnIndent

func (l *Logger) UnIndent()

func (*Logger) Warn

func (l *Logger) Warn(message string)

type Requests

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

Requests sends network requests using `profile` as context

func NewRequests

func NewRequests(profile *UserProfile, logger *Logger, t *testing.T) *Requests

NewRequests returns a new Requests instance

func (*Requests) Delete

func (r *Requests) Delete(path string, withAuth bool) (responseBody []byte, statusCode int)

Delete does a DELETE request

func (*Requests) DeleteDebug

func (r *Requests) DeleteDebug(path string, withAuth bool) (responseBody []byte, statusCode int)

DeleteDebug does a DELETE request while temporarily setting the log level to debug

func (*Requests) Get

func (r *Requests) Get(path string, withAuth bool) (responseBody []byte, statusCode int)

Get does a GET request

func (*Requests) GetDebug

func (r *Requests) GetDebug(path string, withAuth bool) (responseBody []byte, statusCode int)

GetDebug does a get request while temporarily setting the log level to debug

func (*Requests) Post

func (r *Requests) Post(path string, body interface{}, authenticated bool) (responseBody []byte, statusCode int)

Post does a post request

func (*Requests) PostDebug

func (r *Requests) PostDebug(path string, body interface{}, authenticated bool) (responseBody []byte, statusCode int)

PostDebug does a post request while temporarily setting the log level to debug

func (*Requests) Put

func (r *Requests) Put(path string, body interface{}, authenticated bool) (responseBody []byte, statusCode int)

Put does a PUT request

func (*Requests) PutDebug

func (r *Requests) PutDebug(path string, body interface{}, authenticated bool) (responseBody []byte, statusCode int)

PutDebug does a put request while temporarily setting the log level to debug

type UserProfile

type UserProfile struct {
	sync.Mutex

	Name string
	ID   int

	Requests *Requests
	Logger   *Logger
	// contains filtered or unexported fields
}

UserProfile contains a user-contextual data structure for use within the testing process

func NewUserProfile

func NewUserProfile(id int, name string, logger *Logger, t *testing.T) *UserProfile

NewUserProfile returns a new UserProfile

func (*UserProfile) Decrement

func (u *UserProfile) Decrement(key string) int64

Decrement sets an integer in the number cache if it doesn't exist And then decrements it by 1 The resulting value is returned

func (*UserProfile) GetInt

func (u *UserProfile) GetInt(key string) (val int64)

GetInt gets the int value at profile `profileName` and `key` without changing the current profile

func (*UserProfile) GetObject

func (u *UserProfile) GetObject(key string) (val interface{})

GetObject gets an object at `key` for profile `profileName`

func (*UserProfile) GetString

func (u *UserProfile) GetString(key string) string

GetString returns a string value in profile `profileName` at `key` without changing the active profile

func (*UserProfile) Increment

func (u *UserProfile) Increment(key string) int64

Increment sets an integer in the number cache for profile `profileName` if it doesn't exist And then increments it by 1 The resulting value is returned

func (*UserProfile) SetAuthKey

func (u *UserProfile) SetAuthKey(value string) string

SetAuthKey sets the authentication key for network requests

func (*UserProfile) SetInt

func (u *UserProfile) SetInt(name string, val int64) int64

SetInt sets an int value at `name` for profile `profileName`

func (*UserProfile) SetObject

func (u *UserProfile) SetObject(key string, obj interface{})

SetObject sets an object at `name` for the active user profile

func (*UserProfile) SetString

func (u *UserProfile) SetString(key, value string) string

SetString sets a string value at `key` within the active profile

Jump to

Keyboard shortcuts

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