Add client mock to use in unit testing
Opened this issue · 0 comments
twpayne commented
Current Behavior
I'm trying to integrate the 1Password SDK into chezmoi following the request in twpayne/chezmoi#3852. The initial code is in twpayne/chezmoi#3855.
Currently the SDK only provides code for a client to connect to a running 1Password instance. This means that it is not possible to test the SDK integration in a unit test.
Desired Behavior
I would like a way to create a test client so I can test my 1Password SDK integration in a unit test. One way to do this would be with a new ClientOption
, something like:
client, err := onepassword.NewClient(ctx,
onepassword.WithTestVault(vaultID, map[string]onepassword.Item{
itemID: {
// ...
}
}),
)
// ...
actual, err := client.Items.Get(ctx, vaultId, itemId)
if !reflect.DeepEqual(actual, onepassword.Item{ /* ... */ }) {
t.Errorf("error getting item %s from %s", itemId, vaultId)
}
Benefits & Value
This would make it possible to test code using the 1Password SDK, with all the benefits that testing provides.
Additional information
No response