sharded-gotify/test/tmpdir.go

28 lines
552 B
Go

package test
import (
"os"
"path"
)
// TmpDir is a handler to temporary directory.
type TmpDir struct {
path string
}
// Path returns the path to the temporary directory joined by the elements provided.
func (c TmpDir) Path(elem ...string) string {
return path.Join(append([]string{c.path}, elem...)...)
}
// Clean removes the TmpDir.
func (c TmpDir) Clean() error {
return os.RemoveAll(c.path)
}
// NewTmpDir returns a new handle to a tmp dir.
func NewTmpDir(prefix string) TmpDir {
dir, _ := os.MkdirTemp("", prefix)
return TmpDir{dir}
}