7cd28a6fb6
This commit performs refactoring to pull out common service registration objects into a new `client/serviceregistration` package. This new package will form the base point for all client specific service registration functionality. The Consul specific implementation is not moved as it also includes non-service registration implementations; this reduces the blast radius of the changes as well.
37 lines
865 B
Go
37 lines
865 B
Go
package serviceregistration
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_MakeAllocServiceID(t *testing.T) {
|
|
testCases := []struct {
|
|
inputAllocID string
|
|
inputTaskName string
|
|
inputService *structs.Service
|
|
expectedOutput string
|
|
name string
|
|
}{
|
|
{
|
|
inputAllocID: "7ac7c672-1824-6f06-644c-4c249e1578b9",
|
|
inputTaskName: "cache",
|
|
inputService: &structs.Service{
|
|
Name: "redis",
|
|
PortLabel: "db",
|
|
},
|
|
expectedOutput: "_nomad-task-7ac7c672-1824-6f06-644c-4c249e1578b9-cache-redis-db",
|
|
name: "generic 1",
|
|
},
|
|
}
|
|
|
|
for _, tc := range testCases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
actualOutput := MakeAllocServiceID(tc.inputAllocID, tc.inputTaskName, tc.inputService)
|
|
require.Equal(t, tc.expectedOutput, actualOutput)
|
|
})
|
|
}
|
|
}
|