Skip to content

Commit

Permalink
Merge pull request #8 from b13/bugfix/test-expected-permissions
Browse files Browse the repository at this point in the history
Optimize tests, make it more reliable
  • Loading branch information
ochorocho authored Dec 28, 2023
2 parents 7426d9a + 0727fd5 commit 776c6a9
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,60 @@ setup() {
}

@test "Send request from 'web' to the api and see how it is going there" {
result="$(ddev exec "curl -u rabbitmq:rabbitmq --fail -H 'Content-Type: application/json' -X GET http://rabbitmq:15672/api/health/checks/alarms")"
[ "$result" == "{\"status\":\"ok\"}" ]
run ddev exec "curl -s -u rabbitmq:rabbitmq --fail -H 'Content-Type: application/json' -X GET http://rabbitmq:15672/api/health/checks/alarms"

[ "$output" == '{"status":"ok"}' ]
}

@test "Apply configuration defined in config.rabbitmq.yaml" {
ddev rabbitmq apply
}

@test "See expected users" {
result=$(ddev rabbitmqctl list_users --silent --formatter json)
expected='[ {"user":"rabbitmq","tags":["administrator"]},{"user":"ddev-admin","tags":["administrator,management"]} ]'
run ddev rabbitmqctl list_users --silent --formatter json

[ "$(echo "$result" | jq -c -S '.' 2>/dev/null)" == "$(echo "$expected" | jq -c -S '.' 2>/dev/null)" ]
[[ "$output" == *'{"user":"rabbitmq","tags":["administrator"]}'* ]]
[[ "$output" == *'{"user":"ddev-admin","tags":["administrator,management"]}'* ]]
}

@test "See expected vhosts" {
result=$(ddev rabbitmqctl list_vhosts --silent --formatter json)
expected='[ {"name":"/"},{"name":"ddev-vhost"} ]'
run ddev rabbitmqctl list_vhosts --silent --formatter json

[ "$(echo "$result" | jq -c -S '.' 2>/dev/null)" == "$(echo "$expected" | jq -c -S '.' 2>/dev/null)" ]
[[ "$output" == *'{"name":"/"}'* ]]
[[ "$output" == *'{"name":"ddev-vhost"}'* ]]
}

@test "See expected permissions for users in vhost=ddev-vhost" {
result=$(ddev rabbitmqctl list_permissions --silent --formatter json --vhost=ddev-vhost)
expected='[ {"user":"rabbitmq","configure":".*","write":".*","read":".*"} ,{"user":"ddev-admin","configure":".*","write":".*","read":".*"} ]'
run ddev rabbitmqctl list_permissions --silent --formatter json --vhost=ddev-vhost

[ "$(echo "$result" | jq -c -S '.' 2>/dev/null)" == "$(echo "$expected" | jq -c -S '.' 2>/dev/null)" ]
[[ "$output" == *'{"user":"ddev-admin","configure":".*","write":".*","read":".*"}'* ]]
[[ "$output" == *'{"user":"rabbitmq","configure":".*","write":".*","read":".*"}'* ]]
}

@test "Delete/wipe custom configuration" {
ddev rabbitmq wipe
run ddev rabbitmq wipe

[ "$status" -eq 0 ]
}

@test "See only rabbitmq default user" {
result=$(ddev rabbitmqctl list_users --silent --formatter json)
expected='[ {"user":"rabbitmq","tags":["administrator"]} ]'
run ddev rabbitmqctl list_users --silent --formatter json

[ "$(echo "$result" | jq -c -S '.' 2>/dev/null)" == "$(echo "$expected" | jq -c -S '.' 2>/dev/null)" ]
[[ "$output" == *'{"user":"rabbitmq","tags":["administrator"]}'* ]]
[[ "$output" != *'{"user":"ddev-admin","tags":["administrator,management"]}'* ]]
}

@test "See only '/' vhost exists" {
result=$(ddev rabbitmqctl list_vhosts --silent --formatter json)
expected='[ {"name":"/"} ]'
run ddev rabbitmqctl list_vhosts --silent --formatter json

[ "$(echo "$result" | jq -c -S '.' 2>/dev/null)" == "$(echo "$expected" | jq -c -S '.' 2>/dev/null)" ]
[[ "$output" == *'{"name":"/"}'* ]]
[[ "$output" != *'{"name":"ddev-vhost"}'* ]]
}

@test "See error message when trying to list permissions for non-existing vhost" {
run -1 ddev rabbitmqctl list_permissions --silent --formatter json --vhost=ddev-vhost
expected="Virtual host 'ddev-vhost' does not"

[[ $output == *$expected* ]]
[[ $output == *"Virtual host 'ddev-vhost' does not"* ]]
}

@test "Remove addon - see files removed" {
Expand Down

0 comments on commit 776c6a9

Please sign in to comment.