open-nomad/client/fingerprint/memory_test.go
Danielle Tomlinson 66c521ca17 client: Move fingerprint structs to pkg
This removes a cyclical dependency when importing client/structs from
dependencies of the plugin_loader, specifically, drivers. Due to
client/config also depending on the plugin_loader.

It also better reflects the ownership of fingerprint structs, as they
are fairly internal to the fingerprint manager.
2018-12-01 17:10:39 +01:00

62 lines
1.6 KiB
Go

package fingerprint
import (
"testing"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/require"
)
func TestMemoryFingerprint(t *testing.T) {
f := NewMemoryFingerprint(testlog.HCLogger(t))
node := &structs.Node{
Attributes: make(map[string]string),
}
request := &FingerprintRequest{Config: &config.Config{}, Node: node}
var response FingerprintResponse
err := f.Fingerprint(request, &response)
if err != nil {
t.Fatalf("err: %v", err)
}
assertNodeAttributeContains(t, response.Attributes, "memory.totalbytes")
if response.Resources == nil {
t.Fatalf("response resources should not be nil")
}
// COMPAT(0.10): Remove in 0.10
if response.Resources.MemoryMB == 0 {
t.Fatalf("Expected node.Resources.MemoryMB to be non-zero")
}
if response.NodeResources.Memory.MemoryMB == 0 {
t.Fatalf("Expected node.Resources.MemoryMB to be non-zero")
}
}
func TestMemoryFingerprint_Override(t *testing.T) {
f := NewMemoryFingerprint(testlog.HCLogger(t))
node := &structs.Node{
Attributes: make(map[string]string),
}
memoryMB := 15000
request := &FingerprintRequest{Config: &config.Config{MemoryMB: memoryMB}, Node: node}
var response FingerprintResponse
err := f.Fingerprint(request, &response)
if err != nil {
t.Fatalf("err: %v", err)
}
assertNodeAttributeContains(t, response.Attributes, "memory.totalbytes")
require := require.New(t)
require.NotNil(response.Resources)
require.Equal(response.Resources.MemoryMB, memoryMB)
require.EqualValues(response.NodeResources.Memory.MemoryMB, memoryMB)
}