github.com/hspak/nomad@v0.7.2-0.20180309000617-bc4ae22a39a5/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 // Tighten the fingerprinter timeouts 25 if conf.Options == nil { 26 conf.Options = make(map[string]string) 27 } 28 conf.Options[fingerprint.TightenNetworkTimeoutsConfig] = "true" 29 30 if cb != nil { 31 cb(conf) 32 } 33 34 logger := testlog.Logger(t) 35 catalog := consul.NewMockCatalog(logger) 36 mockService := newMockConsulServiceClient(t) 37 mockService.logger = logger 38 client, err := NewClient(conf, catalog, mockService, logger) 39 if err != nil { 40 t.Fatalf("err: %v", err) 41 } 42 return client 43 }