2015-08-27 19:58:37 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
2018-06-13 22:33:25 +00:00
|
|
|
"github.com/hashicorp/nomad/helper/testlog"
|
2015-08-27 19:58:37 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2018-03-28 15:07:15 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2015-08-27 19:58:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMemoryFingerprint(t *testing.T) {
|
2018-09-16 00:48:59 +00:00
|
|
|
f := NewMemoryFingerprint(testlog.HCLogger(t))
|
2015-08-27 19:58:37 +00:00
|
|
|
node := &structs.Node{
|
|
|
|
Attributes: make(map[string]string),
|
|
|
|
}
|
2018-01-24 14:09:53 +00:00
|
|
|
|
2018-12-01 16:10:39 +00:00
|
|
|
request := &FingerprintRequest{Config: &config.Config{}, Node: node}
|
|
|
|
var response FingerprintResponse
|
2018-01-26 16:21:07 +00:00
|
|
|
err := f.Fingerprint(request, &response)
|
2015-08-27 19:58:37 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-01-30 17:57:37 +00:00
|
|
|
assertNodeAttributeContains(t, response.Attributes, "memory.totalbytes")
|
2015-08-27 21:01:47 +00:00
|
|
|
|
2018-01-30 17:57:37 +00:00
|
|
|
if response.Resources == nil {
|
|
|
|
t.Fatalf("response resources should not be nil")
|
|
|
|
}
|
2018-09-30 00:23:41 +00:00
|
|
|
|
|
|
|
// COMPAT(0.10): Remove in 0.10
|
2018-01-30 17:57:37 +00:00
|
|
|
if response.Resources.MemoryMB == 0 {
|
|
|
|
t.Fatalf("Expected node.Resources.MemoryMB to be non-zero")
|
2015-11-07 14:14:25 +00:00
|
|
|
}
|
2018-09-30 00:23:41 +00:00
|
|
|
|
|
|
|
if response.NodeResources.Memory.MemoryMB == 0 {
|
|
|
|
t.Fatalf("Expected node.Resources.MemoryMB to be non-zero")
|
|
|
|
}
|
2015-08-27 19:58:37 +00:00
|
|
|
}
|
2018-03-28 15:07:15 +00:00
|
|
|
|
|
|
|
func TestMemoryFingerprint_Override(t *testing.T) {
|
2018-09-16 00:48:59 +00:00
|
|
|
f := NewMemoryFingerprint(testlog.HCLogger(t))
|
2018-03-28 15:07:15 +00:00
|
|
|
node := &structs.Node{
|
|
|
|
Attributes: make(map[string]string),
|
|
|
|
}
|
|
|
|
|
|
|
|
memoryMB := 15000
|
2018-12-01 16:10:39 +00:00
|
|
|
request := &FingerprintRequest{Config: &config.Config{MemoryMB: memoryMB}, Node: node}
|
|
|
|
var response FingerprintResponse
|
2018-03-28 15:07:15 +00:00
|
|
|
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)
|
2018-09-30 00:23:41 +00:00
|
|
|
require.EqualValues(response.NodeResources.Memory.MemoryMB, memoryMB)
|
2018-03-28 15:07:15 +00:00
|
|
|
}
|