Move tests with external requirements to it tests

This commit is contained in:
Alexandre Archambault 2016-08-15 16:14:32 +02:00
parent 1b0dd4e899
commit 72d0ac9728
No known key found for this signature in database
GPG Key ID: 14640A6839C263A9
6 changed files with 121 additions and 105 deletions

View File

@ -41,7 +41,7 @@ function isMasterOrDevelop() {
# TODO Add coverage once https://github.com/scoverage/sbt-scoverage/issues/111 is fixed
SBT_COMMANDS="compile test"
SBT_COMMANDS="compile test it:test"
if echo "$TRAVIS_SCALA_VERSION" | grep -q "^2\.10"; then
SBT_COMMANDS="$SBT_COMMANDS publishLocal" # to make the scripted tests happy

View File

@ -20,8 +20,8 @@ build_script:
- sbt ++2.10.6 coreJVM/publishLocal cache/publishLocal # to make the scripted tests happy
test_script:
- ps: Start-Job { & java -jar -noverify C:\projects\coursier\coursier launch -r http://dl.bintray.com/scalaz/releases io.get-coursier:http-server-java7_2.11:1.0.0-SNAPSHOT -- -d /C:/projects/coursier/tests/jvm/src/test/resources/test-repo/http/abc.com -u user -P pass -r realm -v }
- sbt ++2.11.8 testsJVM/test # Would node be around for testsJS/test?
- sbt ++2.10.6 testsJVM/test plugin/scripted
- sbt ++2.11.8 testsJVM/test testsJVM/it:test # Would node be around for testsJS/test?
- sbt ++2.10.6 testsJVM/test testsJVM/it:test plugin/scripted
cache:
- C:\sbt\
- C:\Users\appveyor\.ivy2

View File

@ -6,6 +6,8 @@ import MimaKeys.{ previousArtifacts, binaryIssueFilters }
val binaryCompatibilityVersion = "1.0.0-M7"
lazy val IntegrationTest = config("it") extend Test
lazy val releaseSettings = Seq(
publishMavenStyle := true,
licenses := Seq("Apache 2.0" -> url("http://opensource.org/licenses/Apache-2.0")),
@ -249,11 +251,13 @@ lazy val tests = crossProject
.dependsOn(core)
.settings(commonSettings: _*)
.settings(noPublishSettings: _*)
.configs(IntegrationTest)
.settings(Defaults.itSettings: _*)
.settings(
name := "coursier-tests",
libraryDependencies ++= Seq(
"org.scala-lang.modules" %% "scala-async" % "0.9.5" % "provided",
"com.lihaoyi" %%% "utest" % "0.4.3" % "test"
"com.lihaoyi" %%% "utest" % "0.4.3" % "test,it"
),
unmanagedResourceDirectories in Test += (baseDirectory in LocalRootProject).value / "tests" / "shared" / "src" / "test" / "resources",
testFrameworks += new TestFramework("utest.runner.Framework")

View File

@ -0,0 +1,70 @@
package coursier.test
import utest._
import coursier.core.Authentication
import coursier.maven.MavenRepository
object HttpAuthenticationTests extends TestSuite {
val tests = TestSuite {
'httpAuthentication - {
// requires an authenticated HTTP server to be running on localhost:8080 with user 'user'
// and password 'pass'
val address = "localhost:8080"
val user = "user"
val password = "pass"
def printErrorMessage() =
Console.err.println(
Console.RED +
s"HTTP authentication tests require a running HTTP server on $address, requiring " +
s"basic authentication with user '$user' and password '$password', serving the right " +
"files.\n" + Console.RESET +
"Run one from the coursier sources with\n" +
" ./coursier launch -r http://dl.bintray.com/scalaz/releases " +
"io.get-coursier:simple-web-server_2.11:1.0.0-M12 -- " +
"-d tests/jvm/src/test/resources/test-repo/http/abc.com -u user -P pass -r realm -v"
)
* - {
// no authentication -> should fail
val failed = try {
CacheFetchTests.check(
MavenRepository(
s"http://$address"
)
)
printErrorMessage()
false
} catch {
case e: Throwable =>
true
}
assert(failed)
}
* - {
// with authentication -> should work
try {
CacheFetchTests.check(
MavenRepository(
s"http://$address",
authentication = Some(Authentication(user, password))
)
)
} catch {
case e: Throwable =>
printErrorMessage()
throw e
}
}
}
}
}

View File

@ -13,55 +13,55 @@ import scala.util.Try
object CacheFetchTests extends TestSuite {
val tests = TestSuite {
def check(extraRepo: Repository): Unit = {
def check(extraRepo: Repository): Unit = {
val tmpDir = Files.createTempDirectory("coursier-cache-fetch-tests").toFile
val tmpDir = Files.createTempDirectory("coursier-cache-fetch-tests").toFile
def cleanTmpDir() = {
def delete(f: File): Boolean =
if (f.isDirectory) {
val removedContent = Option(f.listFiles()).toSeq.flatten.map(delete).forall(x => x)
val removedDir = f.delete()
def cleanTmpDir() = {
def delete(f: File): Boolean =
if (f.isDirectory) {
val removedContent = Option(f.listFiles()).toSeq.flatten.map(delete).forall(x => x)
val removedDir = f.delete()
removedContent && removedDir
} else
f.delete()
removedContent && removedDir
} else
f.delete()
if (!delete(tmpDir))
Console.err.println(s"Warning: unable to remove temporary directory $tmpDir")
}
val res = try {
val fetch = Fetch.from(
Seq(
extraRepo,
MavenRepository("https://repo1.maven.org/maven2")
),
Cache.fetch(
tmpDir
)
)
val startRes = Resolution(
Set(
Dependency(
Module("com.github.alexarchambault", "coursier_2.11"), "1.0.0-M9-test"
)
)
)
startRes.process.run(fetch).run
} finally {
cleanTmpDir()
}
val errors = res.errors
assert(errors.isEmpty)
if (!delete(tmpDir))
Console.err.println(s"Warning: unable to remove temporary directory $tmpDir")
}
val res = try {
val fetch = Fetch.from(
Seq(
extraRepo,
MavenRepository("https://repo1.maven.org/maven2")
),
Cache.fetch(
tmpDir
)
)
val startRes = Resolution(
Set(
Dependency(
Module("com.github.alexarchambault", "coursier_2.11"), "1.0.0-M9-test"
)
)
)
startRes.process.run(fetch).run
} finally {
cleanTmpDir()
}
val errors = res.errors
assert(errors.isEmpty)
}
val tests = TestSuite {
// using scala-test would allow to put the below comments in the test names...
* - {
@ -84,64 +84,6 @@ object CacheFetchTests extends TestSuite {
check(MavenRepository(s"${TestprotocolHandler.protocol}://foo/"))
}
}
'httpAuthentication - {
// requires an authenticated HTTP server to be running on localhost:8080 with user 'user'
// and password 'pass'
val address = "localhost:8080"
val user = "user"
val password = "pass"
def printErrorMessage() =
Console.err.println(
Console.RED +
s"HTTP authentication tests require a running HTTP server on $address, requiring " +
s"basic authentication with user '$user' and password '$password', serving the right " +
"files.\n" + Console.RESET +
"Run one from the coursier sources with\n" +
" ./coursier launch -r http://dl.bintray.com/scalaz/releases " +
"io.get-coursier:simple-web-server_2.11:1.0.0-M12 -- " +
"-d tests/jvm/src/test/resources/test-repo/http/abc.com -u user -P pass -r realm -v"
)
* - {
// no authentication -> should fail
val failed = try {
check(
MavenRepository(
s"http://$address"
)
)
printErrorMessage()
false
} catch {
case e: Throwable =>
true
}
assert(failed)
}
* - {
// with authentication -> should work
try {
check(
MavenRepository(
s"http://$address",
authentication = Some(Authentication(user, password))
)
)
} catch {
case e: Throwable =>
printErrorMessage()
throw e
}
}
}
}
}