github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/serviceregistration/workload_test.go (about) 1 package serviceregistration 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/nomad/nomad/structs" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestWorkloadServices_RegistrationProvider(t *testing.T) { 11 testCases := []struct { 12 inputWorkloadServices *WorkloadServices 13 expectedOutput string 14 name string 15 }{ 16 { 17 inputWorkloadServices: &WorkloadServices{ 18 Services: nil, 19 }, 20 expectedOutput: "", 21 name: "nil panic check", 22 }, 23 { 24 inputWorkloadServices: &WorkloadServices{ 25 Services: []*structs.Service{ 26 {Provider: structs.ServiceProviderNomad}, 27 }, 28 }, 29 expectedOutput: "nomad", 30 name: "nomad provider", 31 }, 32 { 33 inputWorkloadServices: &WorkloadServices{ 34 Services: []*structs.Service{ 35 {Provider: structs.ServiceProviderConsul}, 36 }, 37 }, 38 expectedOutput: "consul", 39 name: "consul provider", 40 }, 41 } 42 43 for _, tc := range testCases { 44 t.Run(tc.name, func(t *testing.T) { 45 actualOutput := tc.inputWorkloadServices.RegistrationProvider() 46 require.Equal(t, tc.expectedOutput, actualOutput) 47 }) 48 } 49 }