Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
173 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package vaku2 | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
var ( | ||
ErrVaultDelete = errors.New("vault delete") | ||
) | ||
|
||
// PathDelete deletes data at a path | ||
func (c *Client) PathDelete(p string) error { | ||
_, err := c.sourceL.Delete(p) | ||
if err != nil { | ||
return fmt.Errorf("%q: %w", p, ErrVaultDelete) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package vaku2 | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPathDelete(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
name string | ||
give string | ||
giveLogical logical | ||
giveOptions []Option | ||
wantErr error | ||
}{ | ||
{ | ||
name: "delete path", | ||
give: "test/foo", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "nonexistent path", | ||
give: "doesnotexist", | ||
wantErr: nil, | ||
}, | ||
{ | ||
name: "no mount", | ||
give: noMountPrefix, | ||
wantErr: ErrVaultDelete, | ||
}, | ||
{ | ||
name: "error", | ||
give: "delete/foo", | ||
giveLogical: &errLogical{ | ||
err: errInject, | ||
}, | ||
wantErr: ErrVaultDelete, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
ln, apiClient := testServer(t) | ||
defer ln.Close() | ||
|
||
client, err := NewClient(append(tt.giveOptions, WithVaultClient(apiClient))...) | ||
assert.NoError(t, err) | ||
|
||
backupL := client.sourceL | ||
if tt.giveLogical != nil { | ||
client.sourceL = tt.giveLogical | ||
} | ||
|
||
for _, ver := range kvMountVersions { | ||
path := tt.give | ||
if tt.give != noMountPrefix { | ||
path = PathJoin(ver, tt.give) | ||
} | ||
|
||
err := client.PathDelete(path) | ||
assert.True(t, errors.Is(err, tt.wantErr)) | ||
|
||
if tt.give == noMountPrefix { | ||
client.sourceL = backupL | ||
readBack, err := client.PathRead(PathJoin(ver, tt.give)) | ||
if tt.giveLogical != nil { | ||
client.sourceL = tt.giveLogical | ||
} | ||
|
||
assert.NoError(t, err) | ||
assert.Nil(t, readBack) | ||
} | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.