Categorygithub.com/joshcarp/muster
modulepackage
0.0.0-20210812120208-6b3bf3b25359
Repository: https://github.com/joshcarp/muster.git
Documentation: pkg.go.dev

# 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

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Usage is a replacement usage function for the flags package.
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author