open-nomad/client/fingerprint/fingerprint_test.go
Mahmood Ali 293276a457 fingerprint code refactor
Some code cleanup:

* Use a field for setting EC2 metadata instead of env-vars in testing;
but keep environment variables for backward compatibility reasons

* Update tests to use testify
2019-11-26 10:51:28 -05:00

44 lines
1.4 KiB
Go

package fingerprint
// This file contains helper methods for testing fingerprinters
import (
"testing"
"github.com/hashicorp/nomad/client/config"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/require"
)
func assertFingerprintOK(t *testing.T, fp Fingerprint, node *structs.Node) *FingerprintResponse {
request := &FingerprintRequest{Config: new(config.Config), Node: node}
var response FingerprintResponse
err := fp.Fingerprint(request, &response)
require.NoError(t, err)
require.NotEmpty(t, response.Attributes, "Failed to apply node attributes")
return &response
}
func assertNodeAttributeContains(t *testing.T, nodeAttributes map[string]string, attribute string) {
require.NotNil(t, nodeAttributes, "expected an initialized map for node attributes")
require.Contains(t, nodeAttributes, attribute)
require.NotEmpty(t, nodeAttributes[attribute])
}
func assertNodeAttributeEquals(t *testing.T, nodeAttributes map[string]string, attribute string, expected string) {
require.NotNil(t, nodeAttributes, "expected an initialized map for node attributes")
require.Contains(t, nodeAttributes, attribute)
require.Equal(t, expected, nodeAttributes[attribute])
}
func assertNodeLinksContains(t *testing.T, nodeLinks map[string]string, link string) {
require.NotNil(t, nodeLinks, "expected an initialized map for node links")
require.Contains(t, nodeLinks, link)
require.NotEmpty(t, nodeLinks[link])
}