Skip to content

Instantly share code, notes, and snippets.

@VictorCabello
Created April 17, 2015 14:56
Show Gist options
  • Save VictorCabello/b6c909bfe5220b781512 to your computer and use it in GitHub Desktop.
Save VictorCabello/b6c909bfe5220b781512 to your computer and use it in GitHub Desktop.
/**
* Enter: Asking for next, last, first, prev on a GitHub Link header
* Exit: corresponding value for each link
*/
@Test
void getLinkFromHeaderTest(){
// Prepare
def gitHubHeader = """Link: <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=15>; rel="next",
<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34>; rel="last",
<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=1>; rel="first",
<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=13>; rel="prev"
"""
def linkNameList = [
'next' : 'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=15',
'last' : 'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34',
'first': 'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=1',
'prev' : 'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=13']
// Execute
// Validate
linkNameList.each{
linkName, expected ->
assert expected ==
toTest.getLinkFromHeader( linkName, gitHubHeader)
}
}
/**
* Enter: Asking for next, last, first, prev on a GitHub Link header
* Exit: corresponding value for each link
*/
void getLinkFromHeaderTest(){
given:
def gitHubHeader = """
Link: <https://api.github.com/search/code?q=addClass+user%3Amozilla&page=15>; rel="next",
<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34>; rel="last",
<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=1>; rel="first",
<https://api.github.com/search/code?q=addClass+user%3Amozilla&page=13>; rel="prev"
"""
expect:
expectedURL == toTest.getLinkFromHeader( linkName, gitHubHeader)
where:
linkName << [ 'next' , 'last' , 'first', 'prev' ]
expectedURL << [
'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=15',
'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=34',
'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=1',
'https://api.github.com/search/code?q=addClass+user%3Amozilla&page=13']
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment