Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions modules/nf-commons/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dependencies {
testFixturesImplementation(project(":nextflow"))

testImplementation "org.apache.groovy:groovy-json:4.0.29" // needed by wiremock
testImplementation ('com.github.tomakehurst:wiremock:3.0.0-beta-10') { exclude module: 'groovy-all' }
testImplementation ('com.github.tomjankes:wiremock-groovy:0.2.0') { exclude module: 'groovy-all' }
testImplementation ('org.wiremock:wiremock:3.13.1') { exclude module: 'groovy-all' }
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,38 @@ import java.time.ZoneOffset
import java.time.ZonedDateTime

import com.github.tomakehurst.wiremock.junit.WireMockRule
import com.github.tomjankes.wiremock.WireMockGroovy
import nextflow.BuildInfo
import org.junit.Rule
import org.pf4j.PluginRuntimeException
import spock.lang.Specification

import static com.github.tomakehurst.wiremock.client.WireMock.*

class HttpPluginRepositoryTest extends Specification {
@Rule
WireMockRule wiremock = new WireMockRule(0)

def wm
HttpPluginRepository unit

def setup() {
wm = new WireMockGroovy(wiremock.port())
unit = new HttpPluginRepository("test-repo", new URI(wiremock.baseUrl()))
}

// ------------------------------------------------------------------------

def 'prefetch metadata for plugin with no releases'() {
given:
wm.stub {
request {
method 'GET'
url "/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"
}
response {
status 200
body """{
wiremock.stubFor(get(urlEqualTo("/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"))
.willReturn(aResponse()
.withStatus(200)
.withBody("""{
"plugins": [
{
"id": "nf-fake"
}
]
}
"""
}
}
""")))

when:
unit.prefetch([new PluginRef("nf-fake")])
Expand All @@ -57,14 +50,10 @@ class HttpPluginRepositoryTest extends Specification {

def 'prefetch plugin metadata with release'() {
given:
wm.stub {
request {
method 'GET'
url "/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"
}
response {
status 200
body """{
wiremock.stubFor(get(urlEqualTo("/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"))
.willReturn(aResponse()
.withStatus(200)
.withBody("""{
"plugins": [
{
"id": "nf-fake",
Expand All @@ -80,9 +69,7 @@ class HttpPluginRepositoryTest extends Specification {
}
]
}
"""
}
}
""")))

when:
unit.prefetch([new PluginRef("nf-fake")])
Expand Down Expand Up @@ -119,16 +106,10 @@ class HttpPluginRepositoryTest extends Specification {

def 'handle prefetch error when metadata service returns an error response'() {
given:
wm.stub {
request {
method 'GET'
url "/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"
}
response {
status 500
body "Server error!"
}
}
wiremock.stubFor(get(urlEqualTo("/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"))
.willReturn(aResponse()
.withStatus(500)
.withBody("Server error!")))

when:
unit.prefetch([new PluginRef("nf-fake")])
Expand All @@ -145,23 +126,17 @@ class HttpPluginRepositoryTest extends Specification {

def 'handle prefetch error when metadata service sends back incorrectly formatted response'() {
given:
wm.stub {
request {
method 'GET'
url "/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"
}
response {
status 200
body """{
wiremock.stubFor(get(urlEqualTo("/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"))
.willReturn(aResponse()
.withStatus(200)
.withBody("""{
"not-plugins": [
{
"id": "nf-fake"
}
]
}
"""
}
}
""")))

when:
unit.prefetch([new PluginRef("nf-fake")])
Expand All @@ -175,19 +150,13 @@ class HttpPluginRepositoryTest extends Specification {

def 'handle prefetch error caused by nextflow sending a bad request to metadata service'() {
given:
wm.stub {
request {
method 'GET'
url "/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"
}
response {
status 400
body """{
wiremock.stubFor(get(urlEqualTo("/v1/plugins/dependencies?plugins=nf-fake&nextflowVersion=${BuildInfo.version}"))
.willReturn(aResponse()
.withStatus(400)
.withBody("""{
"type": "SOME_ERROR",
"message": "Unparseable request"
}"""
}
}
}""")))

when:
unit.prefetch([new PluginRef("nf-fake")])
Expand All @@ -205,15 +174,11 @@ class HttpPluginRepositoryTest extends Specification {
def utcDateStr = "2023-12-25T14:30:45Z"
def estDateStr = "2023-06-15T09:15:30-05:00"
def cestDateStr = "2023-08-10T16:45:00+02:00"

wm.stub {
request {
method 'GET'
url "/v1/plugins/dependencies?plugins=date-test-plugin&nextflowVersion=${BuildInfo.version}"
}
response {
status 200
body """{

wiremock.stubFor(get(urlEqualTo("/v1/plugins/dependencies?plugins=date-test-plugin&nextflowVersion=${BuildInfo.version}"))
.willReturn(aResponse()
.withStatus(200)
.withBody("""{
"plugins": [
{
"id": "date-test-plugin",
Expand Down Expand Up @@ -251,9 +216,7 @@ class HttpPluginRepositoryTest extends Specification {
}
]
}
"""
}
}
""")))

when:
unit.prefetch([new PluginRef("date-test-plugin")])
Expand Down
3 changes: 1 addition & 2 deletions modules/nf-httpfs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ dependencies {

/* testImplementation inherited from top gradle build file */
testImplementation "org.apache.groovy:groovy-json:4.0.29" // needed by wiremock
testImplementation ('com.github.tomakehurst:wiremock:3.0.0-beta-10') { exclude module: 'groovy-all' }
testImplementation ('com.github.tomjankes:wiremock-groovy:0.2.0') { exclude module: 'groovy-all' }
testImplementation ('org.wiremock:wiremock:3.13.1') { exclude module: 'groovy-all' }

testImplementation(testFixtures(project(":nextflow")))
}
Expand Down
51 changes: 17 additions & 34 deletions modules/nf-httpfs/src/test/nextflow/file/http/HttpFilesTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import java.nio.file.Files
import java.nio.file.Paths

import com.github.tomakehurst.wiremock.junit.WireMockRule
import com.github.tomjankes.wiremock.WireMockGroovy
import com.sun.net.httpserver.BasicAuthenticator
import com.sun.net.httpserver.Headers
import com.sun.net.httpserver.HttpExchange
Expand All @@ -35,6 +34,8 @@ import spock.lang.IgnoreIf
import spock.lang.Specification
import test.TestHelper

import static com.github.tomakehurst.wiremock.client.WireMock.*

/**
*
* @author Paolo Di Tommaso <paolo.ditommaso@gmail.com>
Expand All @@ -47,27 +48,18 @@ class HttpFilesTests extends Specification {
def 'should read http file from WireMock' () {

given:
def wireMock = new WireMockGroovy(wireMockRule.port())
def localhost = "http://localhost:${wireMockRule.port()}"
wireMock.stub {
request {
method "GET"
url "/index.html"
}
response {
status 200
body """a
wireMockRule.stubFor(get(urlEqualTo("/index.html"))
.willReturn(aResponse()
.withStatus(200)
.withBody("""a
b
c
d
"""
headers {
"Content-Type" "text/html"
"Content-Length" "10"
"Last-Modified" "Fri, 04 Nov 2016 21:50:34 GMT"
}
}
}
""")
.withHeader("Content-Type", "text/html")
.withHeader("Content-Length", "10")
.withHeader("Last-Modified", "Fri, 04 Nov 2016 21:50:34 GMT")))

when:
def path = Paths.get(new URI("${localhost}/index.html"))
Expand Down Expand Up @@ -208,23 +200,14 @@ class HttpFilesTests extends Specification {

def 'should read with a newByteChannel' () {
given:
def wireMock = new WireMockGroovy(wireMockRule.port())
def localhost = "http://localhost:${wireMockRule.port()}"
wireMock.stub {
request {
method "GET"
url "/index.txt"
}
response {
status 200
body "01234567890123456789012345678901234567890123456789"
headers {
"Content-Type" "text/html"
"Content-Length" "50"
"Last-Modified" "Fri, 04 Nov 2016 21:50:34 GMT"
}
}
}
wireMockRule.stubFor(get(urlEqualTo("/index.txt"))
.willReturn(aResponse()
.withStatus(200)
.withBody("01234567890123456789012345678901234567890123456789")
.withHeader("Content-Type", "text/html")
.withHeader("Content-Length", "50")
.withHeader("Last-Modified", "Fri, 04 Nov 2016 21:50:34 GMT")))

when:
def path = Paths.get(new URI("${localhost}/index.txt"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import java.nio.file.Files
import java.nio.file.Path

import com.github.tomakehurst.wiremock.junit.WireMockRule
import com.github.tomjankes.wiremock.WireMockGroovy
import org.junit.Rule
import spock.lang.IgnoreIf
import spock.lang.Specification
import spock.lang.Unroll

import static com.github.tomakehurst.wiremock.client.WireMock.*
/**
* Created by emilio on 08/11/16.
*/
Expand Down Expand Up @@ -163,51 +164,29 @@ class XFileSystemProviderTest extends Specification {
@Unroll
def 'should follow a redirect when read a http file '() {
given:
def wireMock = new WireMockGroovy(wireMockRule.port())
def localhost = "http://localhost:${wireMockRule.port()}"
wireMock.stub {
request {
method "GET"
url "/index.html"
}
response {
status HTTP_CODE
headers {
"Location" "${localhost}${REDIRECT_TO}"
}
}
}
wireMock.stub {
request {
method "GET"
url "/index2.html"
}
response {
status HTTP_CODE
headers {
"Location" "${localhost}/target.html"
}
}
}
wireMock.stub {
request {
method "GET"
url "/target.html"
}
response {
status 200
body """a
wireMockRule.stubFor(get(urlEqualTo("/index.html"))
.willReturn(aResponse()
.withStatus(HTTP_CODE)
.withHeader("Location", "${localhost}${REDIRECT_TO}")))

wireMockRule.stubFor(get(urlEqualTo("/index2.html"))
.willReturn(aResponse()
.withStatus(HTTP_CODE)
.withHeader("Location", "${localhost}/target.html")))

wireMockRule.stubFor(get(urlEqualTo("/target.html"))
.willReturn(aResponse()
.withStatus(200)
.withBody("""a
b
c
d
"""
headers {
"Content-Type" "text/html"
"Content-Length" "10"
"Last-Modified" "Fri, 04 Nov 2016 21:50:34 GMT"
}
}
}
""")
.withHeader("Content-Type", "text/html")
.withHeader("Content-Length", "10")
.withHeader("Last-Modified", "Fri, 04 Nov 2016 21:50:34 GMT")))

and:
def provider = new HttpFileSystemProvider()
when:
Expand Down
Loading