open-nomad/client/allocdir/testing.go
Michael Schurter 5957030d18
connect: add unix socket to proxy grpc for envoy (#6232)
* connect: add unix socket to proxy grpc for envoy

Fixes #6124

Implement a L4 proxy from a unix socket inside a network namespace to
Consul's gRPC endpoint on the host. This allows Envoy to connect to
Consul's xDS configuration API.

* connect: pointer receiver on structs with mutexes

* connect: warn on all proxy errors
2019-09-03 08:43:38 -07:00

38 lines
847 B
Go

package allocdir
import (
"io/ioutil"
"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 string) (*AllocDir, func()) {
dir, err := ioutil.TempDir("", prefix)
if err != nil {
t.Fatalf("Couldn't create temp dir: %v", err)
}
allocDir := NewAllocDir(l, dir)
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
}