package main import "testing" func TestIsEncrypted_EncFile_True(t *testing.T) { if !isEncrypted("photo.jpg.enc") { t.Error("expected true for .enc file") } } func TestIsEncrypted_PdfFile_False(t *testing.T) { if isEncrypted("doc.pdf") { t.Error("expected false for .pdf file") } } func TestIsEncrypted_DotEncOnly_True(t *testing.T) { if !isEncrypted(".enc") { t.Error("expected true for '.enc'") } } func TestEncryptedPath_AppendsDotEnc(t *testing.T) { got := encryptedPath("uploads/photo.jpg") want := "uploads/photo.jpg.enc" if got != want { t.Errorf("got %q, want %q", got, want) } } func TestShouldProcessFile_RegularFile_True(t *testing.T) { if !shouldProcessFile(false, "photo.jpg") { t.Error("expected true for regular file") } } func TestShouldProcessFile_Directory_False(t *testing.T) { if shouldProcessFile(true, "uploads") { t.Error("expected false for directory") } } func TestShouldProcessFile_AlreadyEncrypted_False(t *testing.T) { if shouldProcessFile(false, "photo.jpg.enc") { t.Error("expected false for already encrypted file") } } // --- ClassifyFile --- func TestClassifyFile_Directory_SkipDir(t *testing.T) { if got := ClassifyFile(true, "uploads", false); got != ActionSkipDir { t.Errorf("got %d, want ActionSkipDir", got) } } func TestClassifyFile_EncryptedFile_SkipEncrypted(t *testing.T) { if got := ClassifyFile(false, "photo.jpg.enc", false); got != ActionSkipEncrypted { t.Errorf("got %d, want ActionSkipEncrypted", got) } } func TestClassifyFile_DryRun_DryRun(t *testing.T) { if got := ClassifyFile(false, "photo.jpg", true); got != ActionDryRun { t.Errorf("got %d, want ActionDryRun", got) } } func TestClassifyFile_Normal_Encrypt(t *testing.T) { if got := ClassifyFile(false, "photo.jpg", false); got != ActionEncrypt { t.Errorf("got %d, want ActionEncrypt", got) } } // --- ComputeRelPath --- func TestComputeRelPath_Valid(t *testing.T) { got, err := ComputeRelPath("/uploads", "/uploads/photo.jpg") if err != nil { t.Fatalf("unexpected error: %v", err) } if got != "photo.jpg" { t.Errorf("got %q, want %q", got, "photo.jpg") } } func TestComputeRelPath_NestedPath(t *testing.T) { got, err := ComputeRelPath("/uploads", "/uploads/2024/01/photo.jpg") if err != nil { t.Fatalf("unexpected error: %v", err) } want := "2024/01/photo.jpg" if got != want { t.Errorf("got %q, want %q", got, want) } }