2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2015-08-27 19:58:37 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-03-15 12:42:43 +00:00
|
|
|
"github.com/hashicorp/nomad/ci"
|
2015-08-27 19:58:37 +00:00
|
|
|
"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) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(t)
|
|
|
|
|
2019-08-31 14:36:47 +00:00
|
|
|
require := require.New(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)
|
2019-08-31 14:36:47 +00:00
|
|
|
require.NoError(err)
|
2015-08-27 19:58:37 +00:00
|
|
|
|
2018-01-30 17:57:37 +00:00
|
|
|
assertNodeAttributeContains(t, response.Attributes, "memory.totalbytes")
|
2019-09-04 15:09:30 +00:00
|
|
|
require.NotNil(response.Resources, "expected response Resources to not be nil")
|
|
|
|
require.NotZero(response.Resources.MemoryMB, "expected memory to be non-zero")
|
2019-08-31 14:36:47 +00:00
|
|
|
require.NotNil(response.NodeResources, "expected response NodeResources to not be nil")
|
|
|
|
require.NotZero(response.NodeResources.Memory.MemoryMB, "expected memory 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) {
|
2022-03-15 12:42:43 +00:00
|
|
|
ci.Parallel(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)
|
2019-09-04 15:09:30 +00:00
|
|
|
require.NotNil(response.Resources)
|
|
|
|
require.EqualValues(response.Resources.MemoryMB, memoryMB)
|
2019-08-31 14:36:47 +00:00
|
|
|
require.NotNil(response.NodeResources)
|
2018-09-30 00:23:41 +00:00
|
|
|
require.EqualValues(response.NodeResources.Memory.MemoryMB, memoryMB)
|
2018-03-28 15:07:15 +00:00
|
|
|
}
|