open-nomad/client/allocdir/testing.go
Lance Haig 35c17b2e56
deps: Update ioutil deprecated library references to os and io respectively in the client package (#16318)
* Update ioutil deprecated library references to os and io respectively

* Deal with the errors produced.

Add error handling to filEntry info
Add error handling to info
2023-03-08 13:25:10 -06:00

37 lines
840 B
Go

package allocdir
import (
"os"
hclog "github.com/hashicorp/go-hclog"
testing "github.com/mitchellh/go-testing-interface"
)
// TestAllocDir returns a built alloc dir in a temporary directory and cleanup
// func.
func TestAllocDir(t testing.T, l hclog.Logger, prefix, id string) (*AllocDir, func()) {
dir, err := os.MkdirTemp("", prefix)
if err != nil {
t.Fatalf("Couldn't create temp dir: %v", err)
}
allocDir := NewAllocDir(l, dir, id)
cleanup := func() {
if err := os.RemoveAll(dir); err != nil {
t.Logf("error cleaning up alloc dir %q: %v", prefix, err)
}
if err := allocDir.Destroy(); err != nil {
t.Logf("error cleaning up alloc dir %q: %v", prefix, err)
}
}
if err := allocDir.Build(); err != nil {
cleanup()
t.Fatalf("error building alloc dir %q: %v", prefix, err)
}
return allocDir, cleanup
}