github.com/smithx10/nomad@v0.9.1-rc1/client/config/testing.go (about)

     1  package config
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/hashicorp/nomad/helper"
     9  	"github.com/hashicorp/nomad/helper/testlog"
    10  	"github.com/hashicorp/nomad/nomad/mock"
    11  	testing "github.com/mitchellh/go-testing-interface"
    12  )
    13  
    14  // TestClientConfig returns a default client configuration for test clients and
    15  // a cleanup func to remove the state and alloc dirs when finished.
    16  func TestClientConfig(t testing.T) (*Config, func()) {
    17  	conf := DefaultConfig()
    18  	conf.Node = mock.Node()
    19  	conf.Logger = testlog.HCLogger(t)
    20  
    21  	// Create a tempdir to hold state and alloc subdirs
    22  	parent, err := ioutil.TempDir("", "nomadtest")
    23  	if err != nil {
    24  		t.Fatalf("error creating client dir: %v", err)
    25  	}
    26  	cleanup := func() {
    27  		os.RemoveAll(parent)
    28  	}
    29  
    30  	allocDir := filepath.Join(parent, "allocs")
    31  	if err := os.Mkdir(allocDir, 0777); err != nil {
    32  		cleanup()
    33  		t.Fatalf("error creating alloc dir: %v", err)
    34  	}
    35  	conf.AllocDir = allocDir
    36  
    37  	stateDir := filepath.Join(parent, "client")
    38  	if err := os.Mkdir(stateDir, 0777); err != nil {
    39  		cleanup()
    40  		t.Fatalf("error creating alloc dir: %v", err)
    41  	}
    42  	conf.StateDir = stateDir
    43  
    44  	conf.VaultConfig.Enabled = helper.BoolToPtr(false)
    45  	conf.DevMode = true
    46  
    47  	// Loosen GC threshold
    48  	conf.GCDiskUsageThreshold = 98.0
    49  	conf.GCInodeUsageThreshold = 98.0
    50  	return conf, cleanup
    51  }