2025-07-21 17:16:10 +03:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2025-07-27 19:02:05 +03:00
|
|
|
|
|
|
|
"code.uint32.ru/tiny/storage/storageutil"
|
2025-07-21 17:16:10 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2025-07-27 19:02:05 +03:00
|
|
|
client, err := storageutil.NewVaultApiClient(token, addr)
|
|
|
|
|
|
|
|
st := New(client, path)
|
2025-07-21 17:16:10 +03:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|