gopass/internal/backend/crypto_test.go
Ludovic Fernandez b8f0ff8ff2
[chore]: linting (#2840)
Signed-off-by: Fernandez Ludovic <ldez@users.noreply.github.com>
2024-03-25 19:32:57 +01:00

51 lines
1004 B
Go

package backend
import (
"os"
"path/filepath"
"testing"
"github.com/gopasspw/gopass/internal/config"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestDetectCrypto(t *testing.T) {
for _, tc := range []struct {
name string
file string
}{
{
name: "plain",
file: ".plain-id",
},
{
name: "gpg",
file: ".gpg-id",
},
{
name: "age",
file: ".age-recipients",
},
} {
t.Run(tc.name, func(t *testing.T) {
ctx := config.NewContextInMemory()
fsDir := filepath.Join(t.TempDir(), "fs")
_ = os.RemoveAll(fsDir)
require.NoError(t, os.MkdirAll(fsDir, 0o700))
require.NoError(t, os.WriteFile(filepath.Join(fsDir, tc.file), []byte("foo"), 0o600))
r, err := DetectStorage(ctx, fsDir)
require.NoError(t, err)
assert.NotNil(t, r)
assert.Equal(t, "fs", r.Name())
c, err := DetectCrypto(ctx, r)
require.NoError(t, err, tc.name)
require.NotNil(t, c, tc.name)
assert.Equal(t, tc.name, c.Name())
})
}
}