-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from fictivekin/9-service-interface
Peer Service Interface and Config Customizability
- Loading branch information
Showing
13 changed files
with
217 additions
and
116 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
import pytest | ||
|
||
from subnet import ( | ||
ip_address, | ||
IPv4Address, | ||
) | ||
|
||
from wireguard import ( | ||
Config, | ||
Interface, | ||
Peer, | ||
) | ||
|
||
|
||
class MyCustomInterface(Interface): | ||
pass | ||
|
||
|
||
class MyCustomConfig(Config): | ||
pass | ||
|
||
|
||
def test_peer_custom_config_cls(): | ||
address = '192.168.0.2' | ||
dns = '1.1.1.1' | ||
|
||
peer = Peer( | ||
'test-peer', | ||
address=address, | ||
dns=ip_address(dns), | ||
config_cls=MyCustomConfig, | ||
) | ||
|
||
assert isinstance(peer.config, MyCustomConfig) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
('cls',), | ||
[ | ||
(MyCustomInterface,), | ||
(IPv4Address,), | ||
], | ||
) | ||
def test_peer_invalid_custom_config_cls(cls): | ||
address = '192.168.0.2' | ||
dns = '1.1.1.1' | ||
|
||
with pytest.raises(ValueError): | ||
peer = Peer( | ||
'test-peer', | ||
address=address, | ||
dns=ip_address(dns), | ||
config_cls=cls, | ||
) | ||
|
||
|
||
def test_peer_custom_service_cls(): | ||
address = '192.168.0.2' | ||
dns = '1.1.1.1' | ||
|
||
peer = Peer( | ||
'test-peer', | ||
address=address, | ||
dns=ip_address(dns), | ||
service_cls=MyCustomInterface, | ||
) | ||
|
||
assert isinstance(peer.service, MyCustomInterface) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
('cls',), | ||
[ | ||
(MyCustomConfig,), | ||
(IPv4Address,), | ||
], | ||
) | ||
def test_peer_invalid_custom_service_cls(cls): | ||
address = '192.168.0.2' | ||
dns = '1.1.1.1' | ||
|
||
with pytest.raises(ValueError): | ||
peer = Peer( | ||
'test-peer', | ||
address=address, | ||
dns=ip_address(dns), | ||
service_cls=cls, | ||
) |
This file contains 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 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 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.