github.com/kaisenlinux/docker@v0.0.0-20230510090727-ea55db55fac7/swarmkit/api/naming/naming_test.go (about) 1 package naming 2 3 import ( 4 "testing" 5 6 "github.com/docker/swarmkit/api" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestTaskNaming(t *testing.T) { 11 for _, testcase := range []struct { 12 Name string 13 Task *api.Task 14 Expected string 15 }{ 16 { 17 Name: "Basic", 18 Task: &api.Task{ 19 ID: "taskID", 20 Slot: 10, 21 NodeID: "thenodeID", 22 ServiceAnnotations: api.Annotations{ 23 Name: "theservice", 24 }, 25 }, 26 Expected: "theservice.10.taskID", 27 }, 28 { 29 Name: "Annotations", 30 Task: &api.Task{ 31 ID: "taskID", 32 NodeID: "thenodeID", 33 Annotations: api.Annotations{ 34 Name: "thisisthetaskname", 35 }, 36 ServiceAnnotations: api.Annotations{ 37 Name: "theservice", 38 }, 39 }, 40 Expected: "thisisthetaskname", 41 }, 42 { 43 Name: "NoSlot", 44 Task: &api.Task{ 45 ID: "taskID", 46 NodeID: "thenodeID", 47 ServiceAnnotations: api.Annotations{ 48 Name: "theservice", 49 }, 50 }, 51 Expected: "theservice.thenodeID.taskID", 52 }, 53 } { 54 t.Run(testcase.Name, func(t *testing.T) { 55 t.Parallel() 56 name := Task(testcase.Task) 57 assert.Equal(t, name, testcase.Expected) 58 }) 59 } 60 }