feat: add Vault

Co-authored-by: Dmitry Fedotov <dmitry@uint32.ru>
Co-committed-by: Dmitry Fedotov <dmitry@uint32.ru>
This commit is contained in:
2025-07-21 17:16:10 +03:00
committed by dmitry
parent d85dca2195
commit 854de3865b
6 changed files with 261 additions and 13 deletions

View File

@@ -0,0 +1,57 @@
package vault
import (
"bytes"
"os"
"testing"
)
func TestVaultStorage(t *testing.T) {
token, ok := os.LookupEnv("V_TOKEN")
if !ok {
t.Skip("no V_TOKEN")
}
addr, ok := os.LookupEnv("V_ADDR")
if !ok {
t.Skip("no V_ADDR")
}
path, ok := os.LookupEnv("V_PATH")
if !ok {
t.Skip("no V_PATH")
}
t.Log(addr)
t.Log(path)
st, err := Open(token, path, addr)
if err != nil {
t.Fatal(err)
}
testkey := "testkey"
data := []byte("this is a test")
if err := st.Save(testkey, data); err != nil {
t.Error(err)
}
b, err := st.Load(testkey)
if err != nil {
t.Error(err)
}
if !bytes.Equal(data, b) {
t.Errorf("values are not equal, want: %s, have: %s", string(data), string(b))
}
if err := st.Delete(testkey); err != nil {
t.Error(err)
}
b, err = st.Load(testkey)
if err == nil {
t.Log("nil error when loading deleted key")
}
}