M3: add unit tests for config resolution and cryptsetup helpers

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>
This commit is contained in:
2026-03-24 08:00:15 -07:00
parent 26aa202b05
commit ff3147e73b
2 changed files with 176 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
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")
}
}