Files
distrobox/pkg/containermanager/containermanager_test.go
T
Alessio Biancalana 24b31ed834 fix(list): detect containers with overridden manager label (#2116)
When `--additional-flags --label=manager=...` overrides the manager
label at creation time, `distrobox list` would hide the container and
`distrobox rm` would silently no-op (it filters through the same list).
Match the distrobox.* label set alongside `manager` so containers
remain detectable when the manager label is overridden, restoring v1's
loose `*distrobox*` substring behavior.
2026-06-14 13:04:28 +02:00

40 lines
1.2 KiB
Go

package containermanager_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/89luca89/distrobox/pkg/containermanager"
)
func TestContainer_IsDistrobox_StandardManagerLabel(t *testing.T) {
c := containermanager.Container{
Labels: map[string]string{"manager": "distrobox", "distrobox.unshare_groups": "0"},
}
assert.True(t, c.IsDistrobox())
}
// Regression: when the user overrides the manager label via
// `--additional-flags --label=manager=apx`, the container is still a
// distrobox container — the `distrobox.unshare_groups` label is always set on
// creation and is enough to identify it.
func TestContainer_IsDistrobox_ManagerLabelOverridden(t *testing.T) {
c := containermanager.Container{
Labels: map[string]string{"manager": "apx", "distrobox.unshare_groups": "0"},
}
assert.True(t, c.IsDistrobox())
}
func TestContainer_IsDistrobox_NoDistroboxLabels(t *testing.T) {
c := containermanager.Container{
Labels: map[string]string{"manager": "toolbox"},
}
assert.False(t, c.IsDistrobox())
}
func TestContainer_IsDistrobox_NilLabels(t *testing.T) {
c := containermanager.Container{Labels: nil}
assert.False(t, c.IsDistrobox())
}