package client import ( "testing" "github.com/docker/docker/api/types/swarm" "github.com/stretchr/testify/assert" ) func TestGetSecretNames(t *testing.T) { tests := []struct { name string secrets []swarm.Secret expected []string description string }{ { name: "empty secrets list", secrets: []swarm.Secret{}, expected: nil, description: "should return nil for empty input", }, { name: "single secret", secrets: []swarm.Secret{ {Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "database_password"}}}, }, expected: []string{"database_password"}, description: "should return single secret name", }, { name: "multiple secrets", secrets: []swarm.Secret{ {Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "db_password"}}}, {Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "api_key"}}}, {Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "ssl_cert"}}}, }, expected: []string{"db_password", "api_key", "ssl_cert"}, description: "should return all secret names in order", }, { name: "secrets with empty names", secrets: []swarm.Secret{ {Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: ""}}}, {Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "valid_name"}}}, }, expected: []string{"", "valid_name"}, description: "should include empty names if present", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { result := GetSecretNames(tt.secrets) assert.Equal(t, tt.expected, result, tt.description) }) } }