fixtures

package
v1.25.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const SupportedVersions = 0

SupportedVersions is the version number of the fixture template the CLI supports

Variables

View Source
var Edit = func(path string, filedata []byte) ([]byte, error) {
	filename := getFixtureFilenameWithWildcard(path)
	editor, err := git.NewTemporaryFileEditor(filename, filedata)
	if err != nil {
		return nil, err
	}

	return editor.EditContent()
}

Edit is separated into a var so we can mock this in fixtures_test

View Source
var Events = map[string]string{}/* 112 elements not displayed */

Events is a mapping of pre-built trigger events and the corresponding json file

Functions

func EventList

func EventList() string

EventList prints out a padded list of supported trigger events for printing the help file

func EventNames

func EventNames() []string

EventNames returns an array of all the event names

func Trigger added in v1.6.0

func Trigger(ctx context.Context, event string, stripeAccount string, baseURL string, apiKey string, skip, override, add, remove []string, raw string, apiVersion string, edit bool) ([]string, error)

Trigger triggers a Stripe event.

Types

type Fixture

type Fixture struct {
	Fs            afero.Fs
	APIKey        string
	StripeAccount string
	Skip          []string
	Overrides     map[string]interface{}
	Additions     map[string]interface{}
	Removals      map[string]interface{}
	BaseURL       string
	Responses     map[string]gjson.Result
	FixtureData   FixtureData
}

Fixture contains a mapping of an individual fixtures responses for querying

func BuildFromFixtureFile added in v1.7.5

func BuildFromFixtureFile(fs afero.Fs, apiKey, stripeAccount, apiBaseURL, jsonFile string, skip, override, add, remove []string, edit bool) (*Fixture, error)

BuildFromFixtureFile creates a new fixture struct for a file

func BuildFromFixtureString added in v1.7.5

func BuildFromFixtureString(fs afero.Fs, apiKey, stripeAccount, apiBaseURL, raw string) (*Fixture, error)

BuildFromFixtureString creates a new fixture from a string

func NewFixtureFromFile added in v1.7.5

func NewFixtureFromFile(fs afero.Fs, apiKey, stripeAccount, baseURL, file string, skip, override, add, remove []string, edit bool) (*Fixture, error)

NewFixtureFromFile creates a to later run steps for populating test data

func NewFixtureFromRawString added in v1.7.5

func NewFixtureFromRawString(fs afero.Fs, apiKey, stripeAccount, baseURL, raw string) (*Fixture, error)

NewFixtureFromRawString creates fixtures from user inputted string

func (*Fixture) Add added in v1.7.2

func (fxt *Fixture) Add(additions []string) error

Add safely only adds any missing fields that do not already exist. If the field is already on the fixture, it does not get copied over. For that, `Override` should be used

func (*Fixture) Edit added in v1.13.9

func (fxt *Fixture) Edit(path string, filedata []byte) ([]byte, error)

Edit opens the fixture in the git's default IDE to edit directly

func (*Fixture) Execute

func (fxt *Fixture) Execute(ctx context.Context, apiVersion string) ([]string, error)

Execute takes the parsed fixture file and runs through all the requests defined to populate the user's account

func (*Fixture) GetFixtureFileContent added in v1.7.5

func (fxt *Fixture) GetFixtureFileContent() string

GetFixtureFileContent returns the file content of the given fixture file name

func (*Fixture) Override added in v1.7.2

func (fxt *Fixture) Override(overrides []string) error

Override forcefully overrides fields with existing data on a fixture

func (*Fixture) Remove added in v1.7.2

func (fxt *Fixture) Remove(removals []string) error

Remove removes fields from the fixture

func (*Fixture) UpdateEnv

func (fxt *Fixture) UpdateEnv() error

UpdateEnv uses the results of the fixtures command just executed and updates a local .env with the resulting data

type FixtureData added in v1.13.0

type FixtureData struct {
	Meta     MetaFixture       `json:"_meta"`
	Requests []FixtureRequest  `json:"fixtures"`
	Env      map[string]string `json:"env"`
}

FixtureData contains the whole fixture file

type FixtureRequest added in v1.13.0

type FixtureRequest struct {
	Name              string                 `json:"name"`
	ExpectedErrorType string                 `json:"expected_error_type"`
	Path              string                 `json:"path"`
	Method            string                 `json:"method"`
	Params            map[string]interface{} `json:"params"`
	IdempotencyKey    string                 `json:"idempotency_key,omitempty"`
	Context           string                 `json:"context,omitempty"`
	APIBase           string                 `json:"api_base,omitempty"`
	Headers           map[string]string      `json:"headers,omitempty"`
}

FixtureRequest is the individual request payload

type MetaFixture added in v1.13.0

type MetaFixture struct {
	Version         int  `json:"template_version"`
	ExcludeMetadata bool `json:"exclude_metadata"`
}

MetaFixture contains fixture metadata

Jump to

Keyboard shortcuts

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