feat: add Vault
Co-authored-by: Dmitry Fedotov <dmitry@uint32.ru> Co-committed-by: Dmitry Fedotov <dmitry@uint32.ru>
This commit is contained in:
57
internal/vault/vault_test.go
Normal file
57
internal/vault/vault_test.go
Normal 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")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user