muster

command module
v0.0.0-...-6b3bf3b Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2021 License: Apache-2.0 Imports: 20 Imported by: 0

README ¶

Muster

muster is for API developers to automatically generate Must functions for any function that returns a value and an error.

Sometimes it's annoying to create test structs when you need to populate a field with a function that returns (value, error).

Install 📥

go get github.com/joshcarp/muster

Problem 🔥

func TestSomeComplicatedFunc(t *testing.T){
	value, _ := someFunction("blah") // This is annoying
	testCase := SomeComplicatedStruct{
                    Foo: "Bar"
                    ComplicatedField:value
}
//...
}

A better alternative to this is if there was a mustSomethingFunction(string)interface{} that panics if there is an error:

func TestSomeComplicatedFunc(t *testing.T){
	testCase := SomeComplicatedStruct{
                    Foo: "Bar"
                    ComplicatedField: mustSomeFunction("blah") // Much cleaner
}
//...
}

Example 🔧

type Foo struct {

}

func Blah(s int, a Foo) (int, error) {
    return 0, fmt.Errorf("")
}

then run muster . or muster <filename>.go or cat <filename> | muster --stream > output.txt

func MustBlah(s int, a Foo) int {
    val, err := Blah(s, a)
    if err != nil {
        panic(err)
    }
    return val
}

Features 💯

  • Specify more than one file
  • Input from stdin
  • Works with methods
  • Works with external types
  • Include regex
  • Exclude regex
  • Variadic functions

Documentation ¶

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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