-
Notifications
You must be signed in to change notification settings - Fork 71
Adds support for enabling and Disabling relays #572
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2e3e830
add enable and disable relay functions
16d83ee
hook up enable/disable relays to the api
673e26d
add spec and simple doc
25e79ad
track disabled relays in the tracker
5f3a887
don't assume we will get back a relay from the db
4662d39
add fake relay for testing
25c6dd2
add some tests for checking relay enabling and disabling
eb1a076
make fake relay announce block
d98d42d
dry up fake relay
e5a11c2
add some additional notes to the tracker
778cd88
use an if instead of a cond
595b4ee
don't check for membership before removing adding a relay to disabled
0d25b7c
simplify in_tracker?
3c74cd3
consolidate setup code for relay_controller tests
4ccbf29
use a repository interface for relays
a0f6d12
add test to confirm relay deletion
fa8afff
document options
5acacea
use RelaysRepo to alleviate confusion
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,13 @@ defmodule Cog.V1.RelayControllerTest do | |
use Cog.ConnCase | ||
|
||
alias Cog.Models.Relay | ||
alias Cog.Relay.Relays | ||
alias Cog.FakeRelay | ||
alias Cog.Queries | ||
|
||
@create_attrs %{name: "test-1", token: "foo"} | ||
@update_attrs %{enabled: true, description: "My test"} | ||
@disable_attrs %{@update_attrs | enabled: false} | ||
|
||
setup do | ||
# Requests handled by the role controller require this permission | ||
|
@@ -95,6 +98,72 @@ defmodule Cog.V1.RelayControllerTest do | |
assert updated["description"] == @update_attrs.description | ||
end | ||
|
||
test "relays are enabled in more than just name", %{authed: requestor} do | ||
# We create a relay and add a bundle to it so we can query for it in | ||
# 'Cog.Relay.Relays' | ||
relay = relay("relay-enable-relay-1", "foobar") | ||
bundle = bundle("relay-enable-bundle-1") | ||
relay_group = relay_group("relay-enable-group-1") | ||
add_relay_to_group(relay_group.id, relay.id) | ||
assign_bundle_to_group(relay_group.id, bundle.id) | ||
|
||
# We shouldn't see any relays running our bundle yet, because the relay | ||
# has not yet announced it's presence. | ||
assert Relays.relays_running(bundle.name) == [] | ||
|
||
# Relays don't show up as available unless they are online and enabled. | ||
# FakeRelay lets us send announcement messages like a real relay, so Cog | ||
# will add the relay to the available relays list. | ||
FakeRelay.new(relay) |> FakeRelay.get_bundles |> FakeRelay.announce | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, I wonder if some of these could be coalesced behind a single function call. |
||
|
||
# After announcing, our relay should be online but it still won't show up, | ||
# because we haven't enabled it yet. | ||
assert Relays.relays_running(bundle.name) == [] | ||
|
||
# This should enable our relay | ||
conn = api_request(requestor, :put, "/v1/relays/#{relay.id}", | ||
body: %{"relay" => @update_attrs}) | ||
# Confirm that the api thinks the relay is enabled | ||
updated = json_response(conn, 200)["relay"] | ||
assert updated["enabled"] == @update_attrs.enabled | ||
|
||
# Now if we check for relays_running we should see our relay | ||
assert Relays.relays_running(bundle.name) == [relay.id] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really like this test 👍 |
||
end | ||
|
||
test "relays are disabled in more than just name", %{authed: requestor} do | ||
# We create a relay and add a bundle to it so we can query for it in | ||
# 'Cog.Relay.Relays' | ||
relay = relay("relay-disable-1", "foobaz", enabled: true) | ||
bundle = bundle("relay-disable-bundle-1") | ||
relay_group = relay_group("relay-disable-group-1") | ||
add_relay_to_group(relay_group.id, relay.id) | ||
assign_bundle_to_group(relay_group.id, bundle.id) | ||
|
||
# We shouldn't see any relays running our bundle yet, because the relay | ||
# has not yet announced it's presence. | ||
assert Relays.relays_running(bundle.name) == [] | ||
|
||
# Relays don't show up as available unless they are online and enabled. | ||
# FakeRelay lets us send announcement messages like a real relay, so Cog | ||
# will add the relay to the available relays list. | ||
FakeRelay.new(relay) |> FakeRelay.get_bundles |> FakeRelay.announce | ||
|
||
# After announcing, our relay should be online and enabled since we created | ||
# it enabled. | ||
assert Relays.relays_running(bundle.name) == [relay.id] | ||
|
||
# This should disable our relay | ||
conn = api_request(requestor, :put, "/v1/relays/#{relay.id}", | ||
body: %{"relay" => @disable_attrs}) | ||
# Confirm that the api thinks the relay is disabled | ||
updated = json_response(conn, 200)["relay"] | ||
assert updated["enabled"] == @disable_attrs.enabled | ||
|
||
# Now if we check for relays_running we should see nothing again | ||
assert Relays.relays_running(bundle.name) == [] | ||
end | ||
|
||
test "updated token changes token digest", %{authed: requestor} do | ||
relay = relay("test-1", "foobar") | ||
conn = api_request(requestor, :put, "/v1/relays/#{relay.id}", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about making some helper methods that can do all this in one shot, like we now do with
cogctl
.I definitely think we should still have the fine-grained helpers that you've got here, but I think it'd help the tests to put a lot of that tedious setup logic behind some well-named helpers that can do it all in one shot.