helpers

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

README

LaunchDarkly Go Test Helpers

Circle CI

This package centralizes some test support code that is used by LaunchDarkly's Go SDK and related components, and that may be useful in other Go projects.

While this code may be useful in other projects, it is primarily geared toward LaunchDarkly's own development needs and is not meant to provide a large general-purpose framework. It is meant for unit test code and should not be used as a runtime dependency.

Contents

The main package provides general-purpose helper functions.

Subpackage httphelpers provides convenience wrappers for using net/http and net/http/httptest in test code.

Subpackage ldservices is specifically for testing LaunchDarkly SDK client components; it provides HTTP handlers that simulate the service endpoints used by the SDK.

Subpackage testbox provides the ability to write tests-of-tests within the Go testing framework.

Usage

Import any of these packages in your test code:

import (
    "github.com/launchdarkly/go-test-helpers"
    "github.com/launchdarkly/go-test-helpers/httphelpers"
    "github.com/launchdarkly/go-test-helpers/ldservices"
    "github.com/launchdarkly/go-test-helpers/testbox"
)

Breaking changes will only be made in a new major version. It is advisable to use a dependency manager to pin these dependencies to a module version or a major version branch.

Contributing

We encourage pull requests and other contributions from the community. Check out our contributing guidelines for instructions on how to contribute to this project.

About LaunchDarkly

  • LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
    • Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
    • Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
    • Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
    • Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
  • LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out our documentation for a complete list.
  • Explore LaunchDarkly

Documentation

Overview

Package helpers (github.com/launchdarkly/go-test-helpers) contains miscellaneous convenience functions for use in test code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(b bool) *bool

BoolPtr returns a pointer to a bool value. This is useful within expressions where the value is a literal.

func FilePathExists

func FilePathExists(path string) bool

FilePathExists is simply a shortcut for using os.Stat to check for a file's or directory's existence.

func Float64Ptr

func Float64Ptr(n float64) *float64

Float64Ptr returns a pointer to an float64 value. This is useful within expressions where the value is a literal.

func IntPtr

func IntPtr(n int) *int

IntPtr returns a pointer to an int value. This is useful within expressions where the value is a literal.

func StrPtr

func StrPtr(s string) *string

StrPtr returns a pointer to a string value. This is useful within expressions where the value is a literal.

func Uint64Ptr

func Uint64Ptr(n uint64) *uint64

Uint64Ptr returns a pointer to a uint64 value. This is useful within expressions where the value is a literal.

func WithCloser

func WithCloser(closeableObject io.Closer, action func())

WithCloser executes a function and ensures that the given object's Close() method is always called afterward.

This is simply a way to get more specific control over an object's lifetime than using defer. A test function may wish to ensure that an object is closed before some subsequent actions are taken, rather than at the end of the entire test.

If closing the object fails, an error is logged.

func WithTempFile

func WithTempFile(f func(string))

WithTempFile creates a temporary file, passes its name to the given function, then ensures that the file is deleted.

If for any reason it is not possible to create the file, a panic is raised since the test code cannot continue.

If deletion of the file fails (assuming it has not already been deleted) then an error is logged, but there is no panic.

helpers.WithTempFile(func(path string) {
    DoSomethingWithTempFile(path)
}) // the file is deleted at the end of this block

Types

This section is empty.

Directories

Path Synopsis
Package httphelpers contains convenience tools for testing HTTP client code.
Package httphelpers contains convenience tools for testing HTTP client code.
Package ldservices provides HTTP handlers that simulate the behavior of LaunchDarkly service endpoints.
Package ldservices provides HTTP handlers that simulate the behavior of LaunchDarkly service endpoints.
Package testbox provides the ability to run test logic that uses a subset of Go's testing.T methods either inside or outside the regular testing environment.
Package testbox provides the ability to run test logic that uses a subset of Go's testing.T methods either inside or outside the regular testing environment.

Jump to

Keyboard shortcuts

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