open-nomad/client/serviceregistration/workload_test.go
James Rasell 7cd28a6fb6
client: refactor common service registration objects from Consul.
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.
2022-03-15 09:38:30 +01:00

50 lines
1.1 KiB
Go

package serviceregistration
import (
"testing"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/stretchr/testify/require"
)
func TestWorkloadServices_RegistrationProvider(t *testing.T) {
testCases := []struct {
inputWorkloadServices *WorkloadServices
expectedOutput string
name string
}{
{
inputWorkloadServices: &WorkloadServices{
Services: nil,
},
expectedOutput: "",
name: "nil panic check",
},
{
inputWorkloadServices: &WorkloadServices{
Services: []*structs.Service{
{Provider: structs.ServiceProviderNomad},
},
},
expectedOutput: "nomad",
name: "nomad provider",
},
{
inputWorkloadServices: &WorkloadServices{
Services: []*structs.Service{
{Provider: structs.ServiceProviderConsul},
},
},
expectedOutput: "consul",
name: "consul provider",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actualOutput := tc.inputWorkloadServices.RegistrationProvider()
require.Equal(t, tc.expectedOutput, actualOutput)
})
}
}