2015-08-27 00:07:31 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
// This file contains helper methods for testing fingerprinters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/nomad/client/config"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2019-11-26 15:26:25 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2015-08-27 00:07:31 +00:00
|
|
|
)
|
|
|
|
|
2018-12-01 16:10:39 +00:00
|
|
|
func assertFingerprintOK(t *testing.T, fp Fingerprint, node *structs.Node) *FingerprintResponse {
|
|
|
|
request := &FingerprintRequest{Config: new(config.Config), Node: node}
|
|
|
|
var response FingerprintResponse
|
2018-01-26 16:21:07 +00:00
|
|
|
err := fp.Fingerprint(request, &response)
|
2019-11-26 15:26:25 +00:00
|
|
|
require.NoError(t, err)
|
2018-01-24 14:09:53 +00:00
|
|
|
|
2019-11-26 15:26:25 +00:00
|
|
|
require.NotEmpty(t, response.Attributes, "Failed to apply node attributes")
|
2018-01-24 14:09:53 +00:00
|
|
|
|
2018-01-26 16:21:07 +00:00
|
|
|
return &response
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 14:09:53 +00:00
|
|
|
func assertNodeAttributeContains(t *testing.T, nodeAttributes map[string]string, attribute string) {
|
2019-11-26 15:26:25 +00:00
|
|
|
require.NotNil(t, nodeAttributes, "expected an initialized map for node attributes")
|
2018-01-30 17:57:37 +00:00
|
|
|
|
2019-11-26 15:26:25 +00:00
|
|
|
require.Contains(t, nodeAttributes, attribute)
|
|
|
|
require.NotEmpty(t, nodeAttributes[attribute])
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 14:09:53 +00:00
|
|
|
func assertNodeAttributeEquals(t *testing.T, nodeAttributes map[string]string, attribute string, expected string) {
|
2019-11-26 15:26:25 +00:00
|
|
|
require.NotNil(t, nodeAttributes, "expected an initialized map for node attributes")
|
|
|
|
|
|
|
|
require.Contains(t, nodeAttributes, attribute)
|
|
|
|
require.Equal(t, expected, nodeAttributes[attribute])
|
2015-08-31 19:18:40 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 14:09:53 +00:00
|
|
|
func assertNodeLinksContains(t *testing.T, nodeLinks map[string]string, link string) {
|
2019-11-26 15:26:25 +00:00
|
|
|
require.NotNil(t, nodeLinks, "expected an initialized map for node links")
|
|
|
|
|
|
|
|
require.Contains(t, nodeLinks, link)
|
|
|
|
require.NotEmpty(t, nodeLinks[link])
|
2015-08-27 00:07:31 +00:00
|
|
|
}
|