Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement List for KV v1 #24

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions kv_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,29 @@ func (k *KVv1) Read(key string) (*KVv1ReadResponse, error) {
return readRes, nil
}

type KVv1ListResponse struct {
Data struct {
Keys []string `json:"keys"`
} `json:"data"`
}

func (k *KVv1) List(key string) (*KVv1ListResponse, error) {
listRes := &KVv1ListResponse{}

err := k.client.List(
[]string{
pathPrefix,
k.MountPoint,
url.PathEscape(key),
}, nil, listRes, nil,
)
if err != nil {
return nil, err
}

return listRes, nil
}

func (k *KVv1) Delete(key string) error {
err := k.client.Delete(
[]string{
Expand Down
16 changes: 16 additions & 0 deletions kv_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,19 @@ func (s *KVv1TestSuite) TestCreateAndDelete() {
_, readErr := s.client.Read("2b7ff26d-30b7-43ba-96d5-79b4baba9b39")
require.Error(s.T(), readErr)
}

func (s *KVv1TestSuite) TestCreateAndList() {
testKeyValues := make(map[string]string)
testKeyValues["PrivateKey"] = "abcde"

require.NoError(s.T(), s.client.Create("foo", testKeyValues))
require.NoError(s.T(), s.client.Create("foo2", testKeyValues))

list, listErr := s.client.List("")
require.NoError(s.T(), listErr)

require.Contains(s.T(), list.Data.Keys, "foo")
require.Contains(s.T(), list.Data.Keys, "foo2")
require.Len(s.T(), list.Data.Keys, 2)

}
Loading