open-nomad/client/config/testing.go
Michael Schurter f8cdd561f0 client: interpolate driver configurations
Also add missing SetDriverNetwork calls.
2018-11-15 16:25:57 -08:00

52 lines
1.3 KiB
Go

package config
import (
"io/ioutil"
"os"
"path/filepath"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/mitchellh/go-testing-interface"
)
// TestClientConfig returns a default client configuration for test clients and
// a cleanup func to remove the state and alloc dirs when finished.
func TestClientConfig(t testing.T) (*Config, func()) {
conf := DefaultConfig()
conf.Node = mock.Node()
conf.Logger = testlog.HCLogger(t)
// Create a tempdir to hold state and alloc subdirs
parent, err := ioutil.TempDir("", "nomadtest")
if err != nil {
t.Fatalf("error creating client dir: %v", err)
}
cleanup := func() {
os.RemoveAll(parent)
}
allocDir := filepath.Join(parent, "allocs")
if err := os.Mkdir(allocDir, 0777); err != nil {
cleanup()
t.Fatalf("error creating alloc dir: %v", err)
}
conf.AllocDir = allocDir
stateDir := filepath.Join(parent, "client")
if err := os.Mkdir(stateDir, 0777); err != nil {
cleanup()
t.Fatalf("error creating alloc dir: %v", err)
}
conf.StateDir = stateDir
conf.VaultConfig.Enabled = helper.BoolToPtr(false)
conf.DevMode = true
// Loosen GC threshold
conf.GCDiskUsageThreshold = 98.0
conf.GCInodeUsageThreshold = 98.0
return conf, cleanup
}