Merge pull request #5035 from hashicorp/test-client

test: re-eanble periodic fingerprint test
This commit is contained in:
Michael Schurter 2019-01-08 07:37:39 -08:00 committed by GitHub
commit 92f9cda5f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -21,6 +21,7 @@ import (
"github.com/hashicorp/nomad/nomad/structs" "github.com/hashicorp/nomad/nomad/structs"
nconfig "github.com/hashicorp/nomad/nomad/structs/config" nconfig "github.com/hashicorp/nomad/nomad/structs/config"
"github.com/hashicorp/nomad/plugins/device" "github.com/hashicorp/nomad/plugins/device"
"github.com/hashicorp/nomad/plugins/shared/catalog"
psstructs "github.com/hashicorp/nomad/plugins/shared/structs" psstructs "github.com/hashicorp/nomad/plugins/shared/structs"
"github.com/hashicorp/nomad/testutil" "github.com/hashicorp/nomad/testutil"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -163,15 +164,22 @@ func TestClient_Fingerprint(t *testing.T) {
}) })
} }
// TestClient_Fingerprint_Periodic asserts that driver node attributes are
// periodically fingerprinted.
func TestClient_Fingerprint_Periodic(t *testing.T) { func TestClient_Fingerprint_Periodic(t *testing.T) {
t.Skip("missing mock driver plugin implementation")
t.Parallel() t.Parallel()
c1, cleanup := TestClient(t, func(c *config.Config) { c1, cleanup := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{ confs := []*nconfig.PluginConfig{
"test.shutdown_periodic_after": "true", &nconfig.PluginConfig{
"test.shutdown_periodic_duration": "1", Name: "mock_driver",
Config: map[string]interface{}{
"shutdown_periodic_after": true,
"shutdown_periodic_duration": time.Second,
},
},
} }
c.PluginLoader = catalog.TestPluginLoaderWithOptions(t, "", nil, confs)
}) })
defer cleanup() defer cleanup()
@ -219,10 +227,10 @@ func TestClient_Fingerprint_Periodic(t *testing.T) {
return false, fmt.Errorf("mock driver is nil when it should be set on node Drivers") return false, fmt.Errorf("mock driver is nil when it should be set on node Drivers")
} }
if mockDriverInfo.Detected { if mockDriverInfo.Detected {
return false, fmt.Errorf("mock driver should be set as detected") return false, fmt.Errorf("mock driver should not be set as detected")
} }
if mockDriverInfo.Healthy { if mockDriverInfo.Healthy {
return false, fmt.Errorf("mock driver should be set as healthy") return false, fmt.Errorf("mock driver should not be set as healthy")
} }
if mockDriverInfo.HealthDescription == "" { if mockDriverInfo.HealthDescription == "" {
return false, fmt.Errorf("mock driver description should not be empty") return false, fmt.Errorf("mock driver description should not be empty")

View File

@ -11,7 +11,7 @@ import (
"github.com/hashicorp/nomad/helper/testlog" "github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/plugins/shared/catalog" "github.com/hashicorp/nomad/plugins/shared/catalog"
"github.com/hashicorp/nomad/plugins/shared/singleton" "github.com/hashicorp/nomad/plugins/shared/singleton"
"github.com/mitchellh/go-testing-interface" testing "github.com/mitchellh/go-testing-interface"
) )
// TestClient creates an in-memory client for testing purposes and returns a // TestClient creates an in-memory client for testing purposes and returns a
@ -40,6 +40,8 @@ func TestClient(t testing.T, cb func(c *config.Config)) (*Client, func() error)
// Set the plugin loaders // Set the plugin loaders
if conf.PluginLoader == nil { if conf.PluginLoader == nil {
conf.PluginLoader = catalog.TestPluginLoaderWithOptions(t, "", conf.Options, nil) conf.PluginLoader = catalog.TestPluginLoaderWithOptions(t, "", conf.Options, nil)
}
if conf.PluginSingletonLoader == nil {
conf.PluginSingletonLoader = singleton.NewSingletonLoader(logger, conf.PluginLoader) conf.PluginSingletonLoader = singleton.NewSingletonLoader(logger, conf.PluginLoader)
} }
catalog := consul.NewMockCatalog(logger) catalog := consul.NewMockCatalog(logger)