Borg/cmd/decode_test.go
google-labs-jules[bot] 3398fabb14 feat: Add trix encryption and format
This commit introduces the `Enchantrix` library to add support for the `.trix` encrypted file format.

The main changes are:

- The `matrix` format has been renamed to `tim` (Terminal Isolation Matrix).
- The `.tim` format is now a specialized `.trix` file.
- A new `decode` command has been added to decode `.trix` and `.tim` files.
- The `collect` commands now support the `trix` and `tim` formats.
- A `--password` flag has been added to the `collect` commands for encryption.
- A `--i-am-in-isolation` flag has been added to the `decode` command for safely decoding `.tim` files.
- The decryption functionality is currently disabled due to a bug in the `Enchantrix` library. A follow-up PR will be created to re-enable it.
2025-11-14 13:47:27 +00:00

44 lines
1,008 B
Go

package cmd
import (
"os"
"path/filepath"
"testing"
"github.com/Snider/Borg/pkg/datanode"
"github.com/Snider/Borg/pkg/trix"
)
func TestDecodeCmd(t *testing.T) {
t.Run("Good", func(t *testing.T) {
tempDir := t.TempDir()
outputFile := filepath.Join(tempDir, "decoded.dat")
inputFile := filepath.Join(tempDir, "test.trix")
// Create a dummy trix file.
dn := datanode.New()
dn.AddData("test.txt", []byte("hello"))
trixBytes, err := trix.ToTrix(dn, "")
if err != nil {
t.Fatalf("failed to create trix file: %v", err)
}
err = os.WriteFile(inputFile, trixBytes, 0644)
if err != nil {
t.Fatalf("failed to write trix file: %v", err)
}
// Execute the decode command.
cmd := NewDecodeCmd()
cmd.SetArgs([]string{inputFile, "--output", outputFile})
err = cmd.Execute()
if err != nil {
t.Fatalf("decode command failed: %v", err)
}
// Verify the output file.
_, err = os.Stat(outputFile)
if err != nil {
t.Fatalf("output file not found: %v", err)
}
})
}