Tests cover: alias resolution (exact match, device path match, unknown, empty methods default), AliasFor lookup, Load with missing/valid YAML, MapperName generation, and token plugin directory detection. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package cryptsetup
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestMapperName(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
want string
|
|
}{
|
|
{"/dev/sda1", "arca-sda1"},
|
|
{"/dev/nvme0n1p2", "arca-nvme0n1p2"},
|
|
{"/dev/dm-0", "arca-dm-0"},
|
|
{"sda1", "arca-sda1"},
|
|
}
|
|
for _, tt := range tests {
|
|
got := MapperName(tt.input)
|
|
if got != tt.want {
|
|
t.Errorf("MapperName(%q) = %q, want %q", tt.input, got, tt.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestHasTokenPlugins_WithPlugins(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
os.WriteFile(filepath.Join(tmp, "libcryptsetup-token-systemd-fido2.so"), []byte("fake"), 0o644)
|
|
|
|
if !hasTokenPlugins(tmp) {
|
|
t.Error("hasTokenPlugins returned false for dir with plugin")
|
|
}
|
|
}
|
|
|
|
func TestHasTokenPlugins_EmptyDir(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
|
|
if hasTokenPlugins(tmp) {
|
|
t.Error("hasTokenPlugins returned true for empty dir")
|
|
}
|
|
}
|
|
|
|
func TestHasTokenPlugins_NonexistentDir(t *testing.T) {
|
|
if hasTokenPlugins("/nonexistent/path") {
|
|
t.Error("hasTokenPlugins returned true for nonexistent dir")
|
|
}
|
|
}
|