github.com/djenriquez/nomad-1@v0.8.1/client/testing.go (about)

     1  package client
     2  
     3  import (
     4  	"github.com/hashicorp/nomad/client/config"
     5  	"github.com/hashicorp/nomad/client/fingerprint"
     6  	"github.com/hashicorp/nomad/command/agent/consul"
     7  	"github.com/hashicorp/nomad/helper"
     8  	"github.com/hashicorp/nomad/helper/testlog"
     9  	"github.com/hashicorp/nomad/nomad/structs"
    10  	"github.com/mitchellh/go-testing-interface"
    11  )
    12  
    13  // TestClient creates an in-memory client for testing purposes.
    14  func TestClient(t testing.T, cb func(c *config.Config)) *Client {
    15  	conf := config.DefaultConfig()
    16  	conf.VaultConfig.Enabled = helper.BoolToPtr(false)
    17  	conf.DevMode = true
    18  	conf.Node = &structs.Node{
    19  		Reserved: &structs.Resources{
    20  			DiskMB: 0,
    21  		},
    22  	}
    23  
    24  	// Loosen GC threshold
    25  	conf.GCDiskUsageThreshold = 98.0
    26  	conf.GCInodeUsageThreshold = 98.0
    27  
    28  	// Tighten the fingerprinter timeouts
    29  	if conf.Options == nil {
    30  		conf.Options = make(map[string]string)
    31  	}
    32  	conf.Options[fingerprint.TightenNetworkTimeoutsConfig] = "true"
    33  
    34  	if cb != nil {
    35  		cb(conf)
    36  	}
    37  
    38  	logger := testlog.Logger(t)
    39  	catalog := consul.NewMockCatalog(logger)
    40  	mockService := newMockConsulServiceClient(t)
    41  	mockService.logger = logger
    42  	client, err := NewClient(conf, catalog, mockService, logger)
    43  	if err != nil {
    44  		t.Fatalf("err: %v", err)
    45  	}
    46  	return client
    47  }