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

Add client mock to use in unit testing #98

Open
twpayne opened this issue Jul 12, 2024 · 0 comments
Open

Add client mock to use in unit testing #98

twpayne opened this issue Jul 12, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@twpayne
Copy link

twpayne commented Jul 12, 2024

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

@SimonBarendse SimonBarendse changed the title Add test client Add client mock to use in unit testing Jul 31, 2024
@SimonBarendse SimonBarendse added the enhancement New feature or request label Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants