2018-01-12 01:00:30 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
2018-06-11 20:33:18 +00:00
|
|
|
consulApi "github.com/hashicorp/nomad/client/consul"
|
2018-01-12 01:00:30 +00:00
|
|
|
"github.com/hashicorp/nomad/client/fingerprint"
|
|
|
|
"github.com/hashicorp/nomad/command/agent/consul"
|
|
|
|
"github.com/hashicorp/nomad/helper"
|
|
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2018-09-27 01:14:36 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/shared/catalog"
|
|
|
|
"github.com/hashicorp/nomad/plugins/shared/singleton"
|
2018-01-12 01:00:30 +00:00
|
|
|
"github.com/mitchellh/go-testing-interface"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestClient creates an in-memory client for testing purposes.
|
|
|
|
func TestClient(t testing.T, cb func(c *config.Config)) *Client {
|
|
|
|
conf := config.DefaultConfig()
|
2018-09-27 01:14:36 +00:00
|
|
|
logger := testlog.HCLogger(t)
|
|
|
|
conf.Logger = logger
|
2018-01-12 01:00:30 +00:00
|
|
|
conf.VaultConfig.Enabled = helper.BoolToPtr(false)
|
|
|
|
conf.DevMode = true
|
|
|
|
conf.Node = &structs.Node{
|
|
|
|
Reserved: &structs.Resources{
|
|
|
|
DiskMB: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-03-01 00:25:56 +00:00
|
|
|
// Loosen GC threshold
|
|
|
|
conf.GCDiskUsageThreshold = 98.0
|
|
|
|
conf.GCInodeUsageThreshold = 98.0
|
|
|
|
|
2018-01-12 01:00:30 +00:00
|
|
|
// Tighten the fingerprinter timeouts
|
|
|
|
if conf.Options == nil {
|
|
|
|
conf.Options = make(map[string]string)
|
|
|
|
}
|
|
|
|
conf.Options[fingerprint.TightenNetworkTimeoutsConfig] = "true"
|
|
|
|
|
2018-09-27 01:14:36 +00:00
|
|
|
// Set the plugin loaders
|
|
|
|
conf.PluginLoader = catalog.TestPluginLoader(t)
|
|
|
|
conf.PluginSingletonLoader = singleton.NewSingletonLoader(logger, conf.PluginLoader)
|
|
|
|
|
2018-01-12 01:00:30 +00:00
|
|
|
if cb != nil {
|
|
|
|
cb(conf)
|
|
|
|
}
|
|
|
|
|
|
|
|
catalog := consul.NewMockCatalog(logger)
|
2018-09-13 17:43:40 +00:00
|
|
|
mockService := consulApi.NewMockConsulServiceClient(t, logger)
|
|
|
|
client, err := NewClient(conf, catalog, mockService)
|
2018-01-12 01:00:30 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
return client
|
|
|
|
}
|