1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-06-11 10:35:34 +00:00
community.general/tests/unit/plugins/modules/test_onepassword_info.yaml
Alexei Znamensky 7edfbe5562 test(onepassword_info): add unit tests for op CLI v2 rewrite
Cover happy path (already logged in, vault, section field), error paths
(item not found, field not found, no auto_login), and auth flows
(get_token via signin, full login via account add).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-23 11:56:45 +12:00

134 lines
3.4 KiB
YAML

# Copyright (c) 2026, Alexei Znamensky <russoz@gmail.com>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
---
anchors:
env: &env {environ_update: {LANGUAGE: C, LC_ALL: C}, check_rc: false}
item_json: &item_json '{"fields": [{"id": "password", "label": "password", "value": "secret123"}]}'
account_list: &account_list
command: [/testbin/op, account, list]
environ: *env
rc: 0
out: "account info\n"
err: ''
account_get: &account_get
command: [/testbin/op, account, get]
environ: *env
rc: 0
out: ''
err: ''
test_cases:
- id: already_logged_in
input:
search_terms:
- name: My Item
output:
changed: false
onepassword:
"My Item":
password: secret123
mocks:
run_command:
- *account_list
- *account_get
- command: [/testbin/op, item, get, --format, json, My Item]
environ: *env
rc: 0
out: *item_json
err: ''
- id: already_logged_in_with_vault
input:
search_terms:
- name: My Item
vault: Personal
output:
changed: false
onepassword:
"My Item":
password: secret123
mocks:
run_command:
- *account_list
- *account_get
- command: [/testbin/op, item, get, --format, json, My Item, --vault=Personal]
environ: *env
rc: 0
out: *item_json
err: ''
- id: already_logged_in_section_field
input:
search_terms:
- name: My Item
field: Custom Field
section: My Section
output:
changed: false
onepassword:
"My Item":
Custom Field: custom_val
mocks:
run_command:
- *account_list
- *account_get
- command: [/testbin/op, item, get, --format, json, My Item]
environ: *env
rc: 0
out: >-
{"fields": [{"id": "cf_id", "label": "Custom Field", "value": "custom_val",
"section": {"id": "sec_id", "label": "My Section"}}]}
err: ''
- id: item_not_found
input:
search_terms:
- name: Missing Item
output:
failed: true
msg: "Unable to find an item in 1Password named 'Missing Item'."
mocks:
run_command:
- *account_list
- *account_get
- command: [/testbin/op, item, get, --format, json, Missing Item]
environ: *env
rc: 1
out: ''
err: '"Missing Item" not found in vault'
- id: field_not_found
input:
search_terms:
- name: My Item
field: nonexistent
output:
failed: true
msg: "Unable to find an item in 1Password named 'My Item' with the field 'nonexistent'."
mocks:
run_command:
- *account_list
- *account_get
- command: [/testbin/op, item, get, --format, json, My Item]
environ: *env
rc: 0
out: *item_json
err: ''
- id: not_logged_in_no_auto_login
input:
search_terms:
- name: My Item
output:
failed: true
mocks:
run_command:
- command: [/testbin/op, account, list]
environ: *env
rc: 0
out: ''
err: ''
onepassword_config:
config_file_path: ~