set_permissions_globally_command_test: Fix "invalid_regex patterns" test expectations

Testcases are executed in a random order. Unfortunately, this testcase
depended on side effects of other testcases. If this testcase was
executed first, then there were no permissions set and the testcase
would fail.

It now lists permissions before and after the actual test and compare
both.
This commit is contained in:
Jean-Sébastien Pédron 2023-02-08 10:21:10 +01:00
parent 271a7babdf
commit 78e8c595b1
No known key found for this signature in database
GPG Key ID: 39E99761A5FD94CC
1 changed files with 10 additions and 6 deletions

View File

@ -93,19 +93,23 @@ defmodule SetPermissionsGloballyCommandTest do
@tag user: @user
test "run: invalid regex patterns returns an error", context do
p1 = Enum.find(list_permissions(@vhost1), fn x -> x[:user] == context[:user] end)
p2 = Enum.find(list_permissions(@vhost2), fn x -> x[:user] == context[:user] end)
p3 = Enum.find(list_permissions(@vhost3), fn x -> x[:user] == context[:user] end)
assert @command.run(
[context[:user], "^#{context[:user]}-.*", ".*", "*"],
context[:opts]
) == {:error, {:invalid_regexp, '*', {'nothing to repeat', 0}}}
# asserts that the failed command didn't change anything
p1 = Enum.find(list_permissions(@vhost1), fn x -> x[:user] == context[:user] end)
p2 = Enum.find(list_permissions(@vhost2), fn x -> x[:user] == context[:user] end)
p3 = Enum.find(list_permissions(@vhost3), fn x -> x[:user] == context[:user] end)
p4 = Enum.find(list_permissions(@vhost1), fn x -> x[:user] == context[:user] end)
p5 = Enum.find(list_permissions(@vhost2), fn x -> x[:user] == context[:user] end)
p6 = Enum.find(list_permissions(@vhost3), fn x -> x[:user] == context[:user] end)
assert p1 == [user: context[:user], configure: ".*", write: ".*", read: ".*"]
assert p2 == [user: context[:user], configure: ".*", write: ".*", read: ".*"]
assert p3 == [user: context[:user], configure: ".*", write: ".*", read: ".*"]
assert p1 == p4
assert p2 == p5
assert p3 == p6
end
@tag user: @user