2024-07-13 12:34:06 +00:00
|
|
|
package secrets
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_fsStore(t *testing.T) {
|
|
|
|
type payload struct {
|
|
|
|
Foo int
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2024-09-09 14:34:00 +00:00
|
|
|
ctx = context.Background()
|
|
|
|
store = NewFSStore(t.TempDir())
|
|
|
|
id = NewID("testing", "a")
|
2024-07-13 12:34:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var got payload
|
|
|
|
if err := store.Get(ctx, &got, id); !errors.Is(err, ErrNotFound) {
|
|
|
|
t.Fatalf("expected %v, got: %v", ErrNotFound, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
want := payload{Foo: 5}
|
|
|
|
if err := store.Set(ctx, id, want); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := store.Get(ctx, &got, id); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if want != got {
|
|
|
|
t.Fatalf("wanted %+v, got: %+v", want, got)
|
|
|
|
}
|
|
|
|
}
|