factis

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 2 Imported by: 0

README

factis

Go Report Card Documentation

Factis is an object that helps you responsibly track state across multi-step testing scenarios.

Installation

go get -u codeberg.org/ess/factis

How

facts := factis.New()

// Factis can memorize a fact
err := facts.Memorize("sausages", "gold")

// But once it learns something, it is set in its ways
err = facts.Memorize("sausages", "pork")
if err == nil {
  fmt.Println("factis somehow overwrote a state item")
} else {
  fmt.Println("that's a good little factis:", err)
}

// It's also really good at recalling things that it knows
sausages, err := facts.Recall("sausages")
if err == nil {
  fmt.Println("sausages:", sausages)
} else {
  fmt.Println("uh-oh, factis done forgot:", err)
}

// Of course, it's allowed to forget things that it knows
something, err := facts.Forget("sausages")
if err == nil {
  fmt.Println("factis has forgotten that sausages are", something)
} else {
  fmt.Println("dagnabbit, it's refusing to forget sausages:", err)
}

// It's not allowed to forget about things that it doesn't know, though
something, err = facts.Forget("everything you know about lampshades")
if err == nil {
  fmt.Println("wait, factis isn't supposed to know about lampshades")
} else {
  fmt.Println("can't fool ol' factis:", err)
}

Why?

So, I came over from the Ruby world some time back. Over there, it was widely known that tracking state via the normal means (basically globals) was a Bad Scene (TM) that nobody was doing anything about. So, I did something about it.

In short, tracking state via globals is dangerous for a few reasons, not the least of which being that you can't trust that what's in the global var you depend on hasn't been changed out-of-band.

I'm over here in the Go world more these days, and I have it on good authority that it's not a problem at all. We don't use globals for state tracking ... there are no globals!

Well, friend, here's the thing. The keyword isn't "global" here, it's "out-of-band."

So, here's factis to at least my rescue.

History

  • v1.0.0 - Initial Release

Documentation

Overview

package Factis provides a thread-safe object that can be used for responsible state tracking across multi-step test scenarios.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factis

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

Factis is a collection of facts. It is thread-safe. It is used to store facts that are shared between steps.

func From

func From(i interface{}) (*Factis, error)

From returns the factis stored in the given interface. It returns an error if the given interface is not a Factis.

func New

func New() *Factis

New creates a new Factis with an empty set of facts

func (*Factis) Forget

func (f *Factis) Forget(name string) (interface{}, error)

Forget removes the fact stored under the given name. If Factis does not know the fact, it returns an error.

func (*Factis) Memorize

func (f *Factis) Memorize(name string, fact interface{}) error

Memorize stores the given fact under the given name. If Factis already knows the fact, it returns an error.

func (*Factis) Recall

func (f *Factis) Recall(name string) (interface{}, error)

Recall returns the fact stored under the given name. If Factis does not know the fact, it returns an error.

func (*Factis) Reset

func (f *Factis) Reset()

Reset removes all facts from Factis.

Jump to

Keyboard shortcuts

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