github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/client/serviceregistration/id_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 Test_MakeAllocServiceID(t *testing.T) { 11 testCases := []struct { 12 inputAllocID string 13 inputTaskName string 14 inputService *structs.Service 15 expectedOutput string 16 name string 17 }{ 18 { 19 inputAllocID: "7ac7c672-1824-6f06-644c-4c249e1578b9", 20 inputTaskName: "cache", 21 inputService: &structs.Service{ 22 Name: "redis", 23 PortLabel: "db", 24 }, 25 expectedOutput: "_nomad-task-7ac7c672-1824-6f06-644c-4c249e1578b9-cache-redis-db", 26 name: "generic 1", 27 }, 28 } 29 30 for _, tc := range testCases { 31 t.Run(tc.name, func(t *testing.T) { 32 actualOutput := MakeAllocServiceID(tc.inputAllocID, tc.inputTaskName, tc.inputService) 33 require.Equal(t, tc.expectedOutput, actualOutput) 34 }) 35 } 36 }