package testutilimport ()func () (*os.File, *os.File) { , , := os.Pipe()if != nil {panic() }return , }func ( io.ReadCloser) []byte { , := ioutil.ReadAll()if != nil {panic() } .Close()return}// MustMkdirAll calls os.MkdirAll and panics if an error is returned.func ( ...string) {for , := range { := os.MkdirAll(, 0700)if != nil {panic() } }}// MustCreateEmpty creates an empty file, and panics if an error occurs.func ( ...string) {for , := range { , := os.Create()if != nil {panic() } .Close() }}// MustWriteFile calls ioutil.WriteFile and panics if an error occurs.func ( string, []byte, os.FileMode) { := ioutil.WriteFile(, , )if != nil {panic() }}// MustChdir calls os.Chdir and panics if it fails.func ( string) { := os.Chdir()if != nil {panic() }}// Must panics if the error value is not nil. It is typically used like this://// testutil.Must(a_function())//// Where `a_function` returns a single error value. This is useful with// functions like os.Mkdir to succinctly ensure the test fails to proceed if a// "can't happen" failure does, in fact, happen.func ( error) {if != nil {panic() }}
The pages are generated with Goldsv0.2.8-preview. (GOOS=darwin GOARCH=arm64)