Skip to content

Commit

Permalink
history: introduced tests for 'info'
Browse files Browse the repository at this point in the history
  • Loading branch information
edcuba committed Mar 9, 2017
1 parent 4592abb commit 792ac04
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 28 deletions.
14 changes: 7 additions & 7 deletions dnf-docker-test/features/history-1.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ Feature: DNF/Behave test Transaction history - base
Then rpmdb changes are
| State | Packages |
| installed | TestA, TestB |
And history should contain "install -y TestA" with action "Install" and "2" packages
And history should match "install -y TestA" with "Install" and "2" packages

Scenario: Undo last transaction
When I save rpmdb
And I successfully run "dnf history undo last -y"
Then rpmdb changes are
| State | Packages |
| removed | TestA, TestB |
And history should contain "history undo last -y" with action "Erase" and "2" packages
And history should match "history undo last -y" with "Erase" and "2" packages

Scenario: Undo last transaction 2
When I save rpmdb
And I successfully run "dnf history undo last -y"
Then rpmdb changes are
| State | Packages |
| installed | TestA, TestB |
And history should contain "history undo last -y" with action "Install" and "2" packages
And history should match "history undo last -y" with "Install" and "2" packages

Scenario: Undo transaction last-2
When I save rpmdb
And I successfully run "dnf history undo last-2 -y"
Then rpmdb changes are
| State | Packages |
| removed | TestA, TestB |
And history should contain "history undo last-2 -y" with action "Erase" and "2" packages
And history should match "history undo last-2 -y" with "Erase" and "2" packages

Scenario: Redo last transaction
When I save rpmdb
Expand All @@ -66,13 +66,13 @@ Feature: DNF/Behave test Transaction history - base
Then rpmdb changes are
| State | Packages |
| installed | TestA, TestB |
And history should contain "history redo last-1 -y" with action "Install" and "2" packages
And history should match "history redo last-1 -y" with "Install" and "2" packages
When I save rpmdb
And I successfully run "dnf history redo last-1 -y"
Then rpmdb changes are
| State | Packages |
| removed | TestA, TestB |
And history should contain "history redo last-1 -y" with action "Erase" and "2" packages
And history should match "history redo last-1 -y" with "Erase" and "2" packages

Scenario: Update packages
When I save rpmdb
Expand All @@ -87,7 +87,7 @@ Feature: DNF/Behave test Transaction history - base
| State | Packages |
| updated | TestA, TestB, TestC, TestD |
When I successfully run "dnf history"
Then history should contain "update -y" with action "Update" and "4" package
Then history should match "update -y" with "Update" and "4" package

Scenario: Rollback update
When I save rpmdb
Expand Down
69 changes: 56 additions & 13 deletions dnf-docker-test/features/history-2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,64 @@ Feature: DNF/Behave test Transaction history [info, list, userinstalled]
| Match | TestA, TestE |
| Not match | TestB, TestC |

Scenario: History info


Scenario: History info in range


Scenario: History info package


Scenario: History list ranges
Scenario: History list single and ranges
When I save rpmdb
And I successfully run "dnf install -y TestD"
And I successfully run "dnf remove -y TestE"
Then history "last-1..last" should match "install -y TestD" with "Install" and "1" package
And history "list last-1..last" should match "remove -y TestE" with "Erase" and "3" packages
And history "last" should match "remove -y TestE" with "Erase" and "3" packages

Scenario: History list package
When I save rpmdb
And I successfully run "dnf install -y TestC"
Then history "TestC" should match "install -y TestC" with "Install" and "1" package
And history "list TestC" should match "remove -y TestE" with "Erase" and "3" packages

Scenario: History list single
Scenario: History info
When I save rpmdb
Then history info should match
| Key | Value |
| Command Line | install -y TestC |
| Return-Code | Success |
| Install | TestC |
When I successfully run "dnf remove -y TestA"
Then history info should match
| Key | Value |
| Command Line | remove -y TestA |
| Return-Code | Success |
| Erase | TestA, TestB |

Scenario: History info in range
When I save rpmdb
And I successfully run "dnf install -y TestA"
Then history info should match
| Key | Value |
| Command Line | install -y TestA |
| Return-Code | Success |
| Install | TestA, TestB |
When I save rpmdb
And I enable repository "updates"
And I successfully run "dnf update -y"
Then history info should match
| Key | Value |
| Command Line | update -y |
| Return-Code | Success |
| Upgrade | TestA, TestB |
| Upgraded | TestA, TestB |
And history info "last-2..last" should match
| Key | Value |
| Return-Code | Success |
| Upgrade | TestA, TestB |
| Upgraded | TestA, TestB |
| Install | TestA, TestB |
| Erase | TestA, TestB |
And history info "TestA" should match
| Key | Value |
| Return-Code | Success |
| Upgrade | TestA, TestB |
| Upgraded | TestA, TestB |
| Install | TestA, TestB, TestC, TestE |
| Erase | TestA, TestB |

Scenario: History list package

Scenario: List reponame
82 changes: 74 additions & 8 deletions dnf-docker-test/features/steps/command_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ def step_the_command_stream_should_not_match_regexp(ctx, stream, regexp):
text = getattr(ctx.cmd_result, stream)
ctx.assertion.assertNotRegexpMatches(text, regexp)

@then('history should contain "{cmd}" with action "{act}" and "{alt}" package')
@then('history should contain "{cmd}" with action "{act}" and "{alt}" packages')
def step_history_contains(ctx, cmd, act, alt):
step_i_run_command(ctx, "dnf history")
text = getattr(ctx.cmd_result, "stdout")
@then('history should match "{cmd}" with "{act}" and "{alt}" package')
@then('history should match "{cmd}" with "{act}" and "{alt}" packages')
@then('history "{range}" should match "{cmd}" with "{act}" and "{alt}" package')
@then('history "{range}" should match "{cmd}" with "{act}" and "{alt}" packages')
def step_history_contains(ctx, cmd, act, alt, range=""):
step_i_run_command(ctx, 'dnf history ' + range)
text = getattr(ctx.cmd_result, 'stdout')
lines = text.split('\n')
assert len(lines) > 3, 'No output'
del lines[:3]
Expand All @@ -98,7 +100,7 @@ def step_history_contains(ctx, cmd, act, alt):
if set([cmd, act, alt]).issubset(set(words)):
match = True
break
assert match, '"{}" with action "{}" and "{}" packages not matched!'.format(cmd, act, alt)
assert match, '"{}" with "{}" and "{}" packages not matched!'.format(cmd, act, alt)

@then('history userinstalled should')
def step_userinstalled_match(ctx):
Expand All @@ -107,10 +109,74 @@ def pkgs_split(pkgs):
yield pkg.strip()
keys = ['Match', 'Not match']
table = table_utils.parse_kv_table(ctx, ['Action', 'Packages'], keys)
step_i_run_command(ctx, "dnf history userinstalled")
text = getattr(ctx.cmd_result, "stdout")
step_i_run_command(ctx, 'dnf history userinstalled')
text = getattr(ctx.cmd_result, 'stdout')
assert text, 'No output'
for m in pkgs_split(table[keys[0]]): # should be matched
assert m in text, 'Package {} not matched as userinstalled'.format(m)
for n in pkgs_split(table[keys[1]]): # should not be matched
assert n not in text, 'Package {} matched as userinstalled'.format(m)

@then('history info "{spec}" should match')
@then('history info should match')
def step_history_info(ctx, spec=""):
def pkgs_split(pkgs):
return pkgs.split(",")

actions = ['Install', 'Erase', 'Upgrade', 'Upgraded', 'Reinstall', 'Downgrade']
keys = ['Command Line', 'Return-Code'] + actions

table = table_utils.parse_kv_table(ctx, ['Key', 'Value'], keys)
step_i_run_command(ctx, 'dnf history info ' + spec)

text = getattr(ctx.cmd_result, 'stdout')
lines = text.split('\n')
assert text and lines, 'No output'

brpmdb = None
erpmdb = None
cmdline = None
g_cmdline = table['Command Line'] if 'Command Line' in table else None
retcode = None
g_retcode = table['Return-Code'] if 'Return-Code' in table else None

for line in lines:
if 'Begin rpmdb' in line:
brpmdb = line.split(':')

if 'End rpmdb' in line:
erpmdb = line.split(':')

if brpmdb and erpmdb:
assert len(brpmdb) == len(erpmdb) == 3, 'Unexpected rpmdb version format'
assert brpmdb[2] != erpmdb[2], 'No change in rpmdb version'
erpmdb = None

if 'Return-Code' in line and g_retcode:
retcode = line.split(':')
assert len(retcode) == 2, 'Unexpected Return-Code format'
rc = retcode[1].strip()
assert rc == g_retcode, 'Return-Code "{}" not matched by "{}"'.format(rc, g_retcode)

if 'Command Line' in line and g_cmdline:
cmdline = line.split(':')
assert len(cmdline) == 2, 'Unexpected Command Line format'
cmd = cmdline[1].strip()
assert cmd == g_cmdline, 'Command Line "{}" not matched by "{}"'.format(cmd, g_cmdline)

assert brpmdb, 'Begin rpmdb version not found'

if g_cmdline:
assert cmdline, 'Command line not found'

if g_retcode:
assert retcode, 'Return-Code not found'

for key in actions:
if key in table:
pkgs = pkgs_split(table[key])
for line in lines:
for pkg in pkgs:
if pkg in line and key in line:
pkgs.remove(pkg)
assert not pkgs, '"{}" not matched as "{}"'.format(pkgs[0], key)

0 comments on commit 792ac04

Please sign in to comment.