Skip to content

Commit 5438d56

Browse files
Merge pull request #59 from pjk25/add-actions-workflow
Add actions workflow
2 parents 68550e4 + 5b8a857 commit 5438d56

File tree

4 files changed

+97
-26
lines changed

4 files changed

+97
-26
lines changed

.github/workflows/test.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Test
2+
on:
3+
push:
4+
#! branches:
5+
#! - master
6+
#! pull_request:
7+
#! branches:
8+
#! - master
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
services:
13+
rabbitmq:
14+
image: rabbitmq:3.9-management
15+
ports:
16+
- 5672:5672
17+
- 15672:15672
18+
options: >-
19+
--name rabbitmq
20+
env:
21+
RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL: docker exec rabbitmq rabbitmqctl
22+
RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQ_PLUGINS: docker exec rabbitmq rabbitmq-plugins
23+
steps:
24+
- name: Checkout Repository
25+
uses: actions/checkout@v2
26+
- name: Wait for Broker to Finish Starting
27+
run: |
28+
set +e
29+
tries=6;
30+
while true; do
31+
$RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL eval 'true = rabbit:is_running().'
32+
if [[ $? -ne 0 ]]; then
33+
((tries--))
34+
if [[ $tries -gt 0 ]]; then
35+
echo "Rabbit is not yet running, will retry in 10s"
36+
sleep 10
37+
else
38+
exit 1
39+
fi
40+
else
41+
exit 0
42+
fi
43+
done
44+
- name: Configure Broker for Test Suite
45+
run: |
46+
# Reduce retention policy for faster publishing of stats
47+
$RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL eval 'supervisor2:terminate_child(rabbit_mgmt_sup_sup, rabbit_mgmt_sup), application:set_env(rabbitmq_management, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_sup_sup:start_child().' || true
48+
$RUBY_RABBITMQ_HTTP_API_CLIENT_RABBITMQCTL eval 'supervisor2:terminate_child(rabbit_mgmt_agent_sup_sup, rabbit_mgmt_agent_sup), application:set_env(rabbitmq_management_agent, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_agent_sup_sup:start_child().' || true
49+
- uses: ruby/setup-ruby@v1
50+
with:
51+
ruby-version: 2.6 # Not needed with a .ruby-version file
52+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
53+
- name: Run Tests
54+
run: |
55+
bundle exec rspec -cfd spec

bin/ci/before_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ $CTL set_permissions -p / guest ".*" ".*" ".*"
2020

2121
# Reduce retention policy for faster publishing of stats
2222
$CTL eval 'supervisor2:terminate_child(rabbit_mgmt_sup_sup, rabbit_mgmt_sup), application:set_env(rabbitmq_management, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_sup_sup:start_child().' || true
23-
$CTL eval 'supervisor2:terminate_child(rabbit_mgmt_agent_sup_sup, rabbit_mgmt_agent_sup), application:set_env(rabbitmq_management_agent, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_agent_sup_sup:start_child().' || true
23+
$CTL eval 'supervisor2:terminate_child(rabbit_mgmt_agent_sup_sup, rabbit_mgmt_agent_sup), application:set_env(rabbitmq_management_agent, sample_retention_policies, [{global, [{605, 1}]}, {basic, [{605, 1}]}, {detailed, [{10, 1}]}]), rabbit_mgmt_agent_sup_sup:start_child().' || true

lib/rabbitmq/http/client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ def update_topic_permissions_of(vhost, user, attributes)
323323
nil
324324
end
325325

326+
def delete_topic_permissions_of(vhost, user)
327+
decode_resource(@connection.delete("topic-permissions/#{encode_uri_path_segment(vhost)}/#{encode_uri_path_segment(user)}"))
328+
end
329+
326330
def list_users(query = {})
327331
results = decode_resource_collection(@connection.get("users", query))
328332

spec/integration/api_endpoints_spec.rb

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def await_event_propagation
197197
xs = subject.list_connections
198198
f = xs.first
199199

200-
expect(f.name).to match(/127.0.0.1/)
200+
expect(f.name).to match(/(127\.0\.0\.1|172\.18\.0\.1)/)
201201
expect(f.client_properties.product).to eq("Bunny")
202202
end
203203
end
@@ -208,7 +208,7 @@ def await_event_propagation
208208
xs = subject.list_connections
209209
c = subject.connection_info(xs.first.name)
210210

211-
expect(c.name).to match(/127.0.0.1/)
211+
expect(c.name).to match(/(127\.0\.0\.1|172\.18\.0\.1)/)
212212
expect(c.client_properties.product).to eq("Bunny")
213213
end
214214
end
@@ -971,37 +971,49 @@ def await_event_propagation
971971
# Topic permissions
972972
#
973973

974-
describe "GET /api/topic-permissions" do
975-
it "returns a list of topic permissions" do
976-
xs = subject.list_topic_permissions
977-
expect(xs.first.read).to_not be_nil
974+
describe "topic-permissions" do
975+
before :each do
976+
subject.update_topic_permissions_of(
977+
"/",
978+
"guest",
979+
{ exchange: "amq.topic", read: ".*", write: ".*" }
980+
)
981+
end
982+
after :each do
983+
subject.delete_topic_permissions_of("/", "guest")
978984
end
979985

980-
end
986+
describe "GET /api/topic-permissions" do
987+
it "returns a list of topic permissions" do
988+
p, *r = subject.list_topic_permissions
989+
expect(p.read).to_not be_nil
990+
end
991+
end
981992

982-
describe "GET /api/topic-permissions/:vhost/:user" do
983-
it "returns a list of topic permissions of a user in a vhost" do
984-
p = subject.list_topic_permissions_of("/", "guest").first
993+
describe "GET /api/topic-permissions/:vhost/:user" do
994+
it "returns a list of topic permissions of a user in a vhost" do
995+
p, *r = subject.list_topic_permissions_of("/", "guest")
985996

986-
expect(p.exchange).to eq("amq.topic")
987-
expect(p.read).to eq(".*")
988-
expect(p.write).to eq(".*")
997+
expect(p.exchange).to eq("amq.topic")
998+
expect(p.read).to eq(".*")
999+
expect(p.write).to eq(".*")
1000+
end
9891001
end
990-
end
9911002

992-
describe "PUT /api/topic-permissions/:vhost/:user" do
993-
it "updates the topic permissions of a user in a vhost" do
994-
subject.update_topic_permissions_of(
995-
"/",
996-
"guest",
997-
{ exchange: "amq.topic", read: ".*", write: ".*" }
998-
)
1003+
describe "PUT /api/topic-permissions/:vhost/:user" do
1004+
it "updates the topic permissions of a user in a vhost" do
1005+
subject.update_topic_permissions_of(
1006+
"/",
1007+
"guest",
1008+
{ exchange: "amq.topic", read: ".*", write: ".foo" }
1009+
)
9991010

1000-
p = subject.list_topic_permissions_of("/", "guest").first
1011+
p = subject.list_topic_permissions_of("/", "guest").first
10011012

1002-
expect(p.exchange).to eq("amq.topic")
1003-
expect(p.read).to eq(".*")
1004-
expect(p.write).to eq(".*")
1013+
expect(p.exchange).to eq("amq.topic")
1014+
expect(p.read).to eq(".*")
1015+
expect(p.write).to eq(".foo")
1016+
end
10051017
end
10061018
end
10071019

0 commit comments

Comments
 (0)