Skip to content

Commit

Permalink
Merge pull request #31 from Comcast/cleanup
Browse files Browse the repository at this point in the history
Sort keys for consistency and testing
  • Loading branch information
lewg authored Dec 22, 2023
2 parents 6133c59 + 75a6605 commit 26b17a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
10 changes: 9 additions & 1 deletion reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"slices"
"strings"

"github.com/hashicorp/vault-client-go"
Expand Down Expand Up @@ -80,7 +81,14 @@ func (s KVSecretBlock) GetOutput(ctx context.Context, r *Reader) (OutputList, er
}
return nil, fmt.Errorf("error reading path '%s': %w", s.Path, err)
}
for varName, varKey := range s.Vars {
// For testing purposes, we want to order this
envVars := []string{}
for varName := range s.Vars {
envVars = append(envVars, varName)
}
slices.Sort(envVars)
for _, varName := range envVars {
varKey := s.Vars[varName]
if _, hasValue := resp.Data.Data[varKey]; !hasValue {
return nil, fmt.Errorf("key %s not found in path %s", varKey, s.Path)
}
Expand Down
12 changes: 9 additions & 3 deletions reader/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestKVSecretBlock_GetOutput(t *testing.T) {
// KV Data
switch r.URL.Path {
case "/v1/kv2/data/test":
resp = []byte(`{"request_id":"bf3b02c0-096e-84d3-dad7-196aa9f112ed","lease_id":"","renewable":false,"lease_duration":0,"data":{"data":{"one":"1","two":"2"},"metadata":{"created_time":"2023-12-20T15:32:32.814115685Z","custom_metadata":null,"deletion_time":"","destroyed":false,"version":1}},"wrap_info":null,"warnings":null,"auth":null}`)
resp = []byte(`{"request_id":"bf3b02c0-096e-84d3-dad7-196aa9f112ed","lease_id":"","renewable":false,"lease_duration":0,"data":{"data":{"one":"1","two":"2","three":"3"},"metadata":{"created_time":"2023-12-20T15:32:32.814115685Z","custom_metadata":null,"deletion_time":"","destroyed":false,"version":1}},"wrap_info":null,"warnings":null,"auth":null}`)
case "/v1/kv/test":
resp = []byte(`{"request_id":"63c8c31b-f03f-81ac-cfaa-324239789c3f","lease_id":"","renewable":false,"lease_duration":2764800,"data":{"value":"old"},"wrap_info":null,"warnings":null,"auth":null}`)
default:
Expand Down Expand Up @@ -258,8 +258,9 @@ func TestKVSecretBlock_GetOutput(t *testing.T) {
fields: fields{
Path: "kv2/test",
Vars: KVSecret{
"ONE": "one",
"TWO": "two",
"ONE": "one",
"TWO": "two",
"THREE": "three",
},
},
want: OutputList{
Expand All @@ -268,6 +269,11 @@ func TestKVSecretBlock_GetOutput(t *testing.T) {
Value: "1",
Comment: "Path: kv2/test, Key: one",
},
{
Key: "THREE",
Value: "3",
Comment: "Path: kv2/test, Key: three",
},
{
Key: "TWO",
Value: "2",
Expand Down

0 comments on commit 26b17a4

Please sign in to comment.