Skip to content

Commit

Permalink
Add ability to retrieve all the tunnels info at once (#520) (#523)
Browse files Browse the repository at this point in the history
* Add ability to retrieve all the tunnels info at once

* Update SauceConnectEndpointTest.java

---------

Co-authored-by: Valery Yatsynovich <[email protected]>
  • Loading branch information
diemol and valfirst authored May 27, 2024
1 parent 2c254ec commit c523b35
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@ public SauceConnectEndpoint(String username, String accessKey, DataCenter dataCe
}

/**
* Returns Tunnel IDs or Tunnels Info for any currently running tunnels launched by or shared with the specified user.
* Documentation is
* <a href="https://docs.saucelabs.com/dev/api/connect/#get-tunnels-for-a-user">here</a>
* Returns Tunnel IDs for any currently running tunnels launched by the specified user.
* Documentation is <a href="https://docs.saucelabs.com/dev/api/connect/#get-tunnels-for-a-user">here</a>.
*/
public List<String> getTunnelsForAUser() throws IOException {
return getTunnelsForAUser(this.username);
}

/**
* Returns Tunnel IDs or Tunnels Info for any currently running tunnels launched by or shared with the specified user.
* Documentation is
* <a href="https://docs.saucelabs.com/dev/api/connect/#get-tunnels-for-a-user">here</a>
* Returns Tunnels Info for any currently running tunnels launched by the specified user.
* Documentation is <a href="https://docs.saucelabs.com/dev/api/connect/#get-tunnels-for-a-user">here</a>.
*/
public List<TunnelInformation> getTunnelsInformationForAUser() throws IOException {
return getTunnelsInformationForAUser(this.username);
}

/**
* Returns Tunnel IDs for any currently running tunnels launched by the specified user.
* Documentation is <a href="https://docs.saucelabs.com/dev/api/connect/#get-tunnels-for-a-user">here</a>.
*
* @param username Sauce Labs username
*/
Expand All @@ -48,6 +54,18 @@ public List<String> getTunnelsForAUser(String username) throws IOException {
return deserializeJSONArray(request(url, HttpMethod.GET), String.class);
}

/**
* Returns Tunnels Info for any currently running tunnels launched by the specified user.
* Documentation is <a href="https://docs.saucelabs.com/dev/api/connect/#get-tunnels-for-a-user">here</a>.
*
* @param username Sauce Labs username
*/
public List<TunnelInformation> getTunnelsInformationForAUser(String username) throws IOException {
String url = getBaseEndpoint() + username + "/tunnels?full=true";

return deserializeJSONArray(request(url, HttpMethod.GET), TunnelInformation.class);
}

/**
* Returns information about the specified tunnel.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public void getTunnelsForAUserTest(DataCenter dataCenter) throws IOException {
Assertions.assertFalse(tunnelIDs.isEmpty());
}

@ParameterizedTest
@EnumSource(DataCenter.class)
public void getTunnelsInformationForAUserTest(DataCenter dataCenter) throws IOException {
SauceREST sauceREST = new SauceREST(dataCenter);
SauceConnectEndpoint sauceConnectEndpoint = sauceREST.getSauceConnectEndpoint();

List<TunnelInformation> tunnelsInfo = sauceConnectEndpoint.getTunnelsInformationForAUser();

Assertions.assertFalse(tunnelsInfo.isEmpty());
}

@ParameterizedTest
@EnumSource(DataCenter.class)
public void getTunnelInformationTest(DataCenter dataCenter) throws IOException {
Expand All @@ -99,10 +110,9 @@ public void getTunnelInformationTest(DataCenter dataCenter) throws IOException {

List<String> tunnelIDs = sauceConnectEndpoint.getTunnelsForAUser();

Assertions.assertFalse(tunnelIDs.isEmpty());
for (String tunnelID : tunnelIDs) {
TunnelInformation tunnelInformation = sauceConnectEndpoint.getTunnelInformation(tunnelID);

Assertions.assertFalse(tunnelIDs.isEmpty());
Assertions.assertNotNull(tunnelInformation);
}
}
Expand Down

0 comments on commit c523b35

Please sign in to comment.