Run test repo from a more practical script (#901)

This commit is contained in:
Alexandre Archambault 2018-09-22 18:32:40 +02:00 committed by GitHub
parent 08d0375f7e
commit 6198ef85f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 89 additions and 84 deletions

View File

@ -15,17 +15,24 @@ install:
- cmd: SET PATH=C:\sbt\sbt\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET SBT_OPTS=-Xmx4g -Xss2m
- git submodule update --init --recursive
environment:
TEST_REPOSITORY_HOST: localhost
TEST_REPOSITORY_PORT: 8080
TEST_REPOSITORY_USER: user
TEST_REPOSITORY_PASSWORD: pass
TEST_REPOSITORY: http://localhost:8080
build_script:
- ps: Start-Job -filepath .\scripts\start-it-auth-server.ps1 -ArgumentList $pwd, $env:TEST_REPOSITORY_HOST, $env:TEST_REPOSITORY_PORT, $env:TEST_REPOSITORY_USER, $env:TEST_REPOSITORY_PASSWORD
- sbt scala212 coreJVM/publishLocal cacheJVM/publishLocal extra/publishLocal scalazJVM/publishLocal cli/publishLocal
- sbt scala211 compile coreJVM/publishLocal
- sbt scala210 compile
test_script:
- ps: Start-Job -filepath .\scripts\start-it-auth-server.ps1 -ArgumentList $pwd
- ps: Start-Sleep -s 15 # wait for the first server to have downloaded its dependencies
- ps: Start-Job -filepath .\scripts\start-it-no-listing-server.ps1 -ArgumentList $pwd
- sbt scala212 testsJVM/test testsJVM/it:test # Would node be around for testsJS/test?
- sbt scala211 testsJVM/test testsJVM/it:test
- sbt scala210 testsJVM/test testsJVM/it:test
- sbt scala212 testsJVM/test
- sbt scala211 testsJVM/test
- sbt scala210 testsJVM/test
- sbt scala212 testsJVM/it:test
- sbt scala211 testsJVM/it:test
- sbt scala210 testsJVM/it:test
- sbt scala212 "sbt-coursier/scripted sbt-coursier/simple" "sbt-shading/scripted sbt-shading/*" # for sbt 1.0
- sbt scala210 "sbt-coursier/scripted sbt-coursier/*" "sbt-coursier/scripted sbt-coursier-0.13/*" "sbt-shading/scripted sbt-shading/*" "sbt-shading/scripted sbt-shading-0.13/*" # for sbt 0.13
branches:

View File

@ -1,6 +1,6 @@
scalaVersion := "2.11.8"
resolvers += "authenticated" at "http://localhost:8080"
resolvers += "authenticated" at sys.env("TEST_REPOSITORY")
coursierCredentials += "authenticated" -> coursier.Credentials(file("credentials"))

View File

@ -1,8 +1,13 @@
scalaVersion := "2.11.8"
resolvers += "authenticated" at "http://localhost:8080"
resolvers += "authenticated" at sys.env("TEST_REPOSITORY")
coursierUseSbtCredentials := true
credentials += Credentials("", "localhost", "user", "pass")
credentials += Credentials(
"",
sys.env("TEST_REPOSITORY_HOST"),
sys.env("TEST_REPOSITORY_USER"),
sys.env("TEST_REPOSITORY_PASSWORD")
)
libraryDependencies += "com.abc" % "test" % "0.1"

View File

@ -1,7 +1,10 @@
scalaVersion := "2.11.8"
resolvers += "authenticated" at "http://localhost:8080"
resolvers += "authenticated" at sys.env("TEST_REPOSITORY")
coursierCredentials += "authenticated" -> coursier.Credentials("user", "pass")
coursierCredentials += "authenticated" -> coursier.Credentials(
sys.env("TEST_REPOSITORY_USER"),
sys.env("TEST_REPOSITORY_PASSWORD")
)
libraryDependencies += "com.abc" % "test" % "0.1"

View File

@ -1,20 +0,0 @@
#!/usr/bin/env bash
set -e
VERSION="1.0.0"
cd "$(dirname "$0")/.."
# synchronously fill cache so that two runs of this script don't try to download
# a same file at the same time (and one of them fail because of locks)
./coursier fetch \
"io.get-coursier:http-server_2.12:$VERSION" \
-r https://dl.bintray.com/scalaz/releases
./coursier launch \
"io.get-coursier:http-server_2.12:$VERSION" \
-- \
-d tests/jvm/src/test/resources/test-repo/http/abc.com \
-u user -P pass -r realm \
-v \
"$@" &

View File

@ -1,3 +1,3 @@
# see https://stackoverflow.com/questions/2224350/powershell-start-job-working-directory/2246542#2246542
Set-Location $args[0]
& java -jar -noverify coursier launch io.get-coursier:http-server_2.12:1.0.0 -- -d tests/jvm/src/test/resources/test-repo/http/abc.com -u user -P pass -r realm --port 8080 --list-pages -v
& java -jar -noverify coursier launch io.get-coursier:http-server_2.12:1.0.0 -- -d tests/jvm/src/test/resources/test-repo/http/abc.com -u $args[3] -P $args[4] -r realm --host $args[1] --port $args[2] -v

View File

@ -1,3 +0,0 @@
# see https://stackoverflow.com/questions/2224350/powershell-start-job-working-directory/2246542#2246542
Set-Location $args[0]
& java -jar -noverify coursier launch io.get-coursier:http-server_2.12:1.0.0 -- -d tests/jvm/src/test/resources/test-repo/http/abc.com -u user -P pass -r realm --port 8081 -v

View File

@ -13,19 +13,9 @@ downloadInstallSbtExtras() {
chmod +x bin/sbt
}
launchTestRepo() {
./scripts/launch-test-repo.sh "$@"
}
integrationTestsRequirements() {
# Required for ~/.ivy2/local repo tests
sbt scala211 coreJVM/publishLocal scala212 cli/publishLocal
# Required for HTTP authentication tests
launchTestRepo --port 8080 --list-pages
# Required for missing directory listing tests (no --list-pages)
launchTestRepo --port 8081
}
isScalaJs() {
@ -43,10 +33,11 @@ sbtShading() {
runSbtCoursierTests() {
addPgpKeys
if [ "$SCALA_VERSION" = "2.10" ]; then
sbt scalaFromEnv "sbt-coursier/scripted sbt-coursier/*" "sbt-coursier/scripted sbt-coursier-0.13/*"
CMDS=("sbt-coursier/scripted sbt-coursier/*" "sbt-coursier/scripted sbt-coursier-0.13/*")
else
sbt scalaFromEnv "sbt-coursier/scripted sbt-coursier/simple" # full scripted suite currently taking too long on Travis CI...
CMDS=("sbt-coursier/scripted sbt-coursier/simple") # full scripted suite currently taking too long on Travis CI...
fi
./scripts/with-test-repo.sh sbt scalaFromEnv "${CMD[@]}"
sbt scalaFromEnv sbt-pgp-coursier/scripted
}
@ -76,7 +67,7 @@ runJvmTests() {
IT="jvm/it:test"
fi
sbt scalaFromEnv jvm/test $IT
./scripts/with-test-repo.sh sbt scalaFromEnv jvm/test $IT
}
validateReadme() {

45
scripts/with-test-repo.sh Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -e
cd "$(dirname "$0")/.."
SERVER_PID=""
cleanup() {
if [ ! -z "$SERVER_PID" ]; then
echo "Terminating background HTTP server"
kill -15 "$SERVER_PID"
while kill -0 "$SERVER_PID" >/dev/null 2>&1; do
echo "Server still running"
sleep 1
kill -15 "$SERVER_PID" >/dev/null 2>&1 || true
done
echo "Server terminated"
fi
}
trap cleanup EXIT INT TERM
export TEST_REPOSITORY_HOST="localhost"
export TEST_REPOSITORY_PORT="8080"
export TEST_REPOSITORY_USER="user"
export TEST_REPOSITORY_PASSWORD="pass"
export TEST_REPOSITORY="http://$TEST_REPOSITORY_HOST:$TEST_REPOSITORY_PORT"
# see https://unix.stackexchange.com/questions/90244/bash-run-command-in-background-and-capture-pid
runServerBg() {
java -jar ./coursier launch \
"io.get-coursier:http-server_2.12:1.0.0" \
-- \
-d tests/jvm/src/test/resources/test-repo/http/abc.com \
-u "$TEST_REPOSITORY_USER" -P "$TEST_REPOSITORY_PASSWORD" -r realm \
-v \
--host "$TEST_REPOSITORY_HOST" \
--port "$TEST_REPOSITORY_PORT" &
SERVER_PID="$!"
}
runServerBg
"$@"

View File

@ -6,11 +6,11 @@ import utest._
object DirectoryListingTests extends TestSuite {
val user = "user"
val password = "pass"
val user = sys.env("TEST_REPOSITORY_USER")
val password = sys.env("TEST_REPOSITORY_PASSWORD")
val repo = MavenRepository(
"http://localhost:8080",
sys.env.getOrElse("TEST_REPOSITORY", sys.error("TEST_REPOSITORY not set")),
authentication = Some(Authentication(user, password))
)

View File

@ -9,39 +9,22 @@ object HttpAuthenticationTests extends TestSuite {
val tests = Tests {
'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 https://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"
)
val testRepo = sys.env.getOrElse("TEST_REPOSITORY", sys.error("TEST_REPOSITORY not set"))
val user = sys.env.getOrElse("TEST_REPOSITORY_USER", sys.error("TEST_REPOSITORY_USER not set"))
val password = sys.env.getOrElse("TEST_REPOSITORY_PASSWORD", sys.error("TEST_REPOSITORY_PASSWORD not set"))
* - {
// no authentication -> should fail
val failed = try {
CacheFetchTests.check(
MavenRepository(
s"http://$address"
)
MavenRepository(testRepo)
)
printErrorMessage()
false
} catch {
case e: Throwable =>
case _: Throwable =>
true
}
@ -51,18 +34,12 @@ object HttpAuthenticationTests extends TestSuite {
* - {
// with authentication -> should work
try {
CacheFetchTests.check(
MavenRepository(
s"http://$address",
authentication = Some(Authentication(user, password))
)
CacheFetchTests.check(
MavenRepository(
testRepo,
authentication = Some(Authentication(user, password))
)
} catch {
case e: Throwable =>
printErrorMessage()
throw e
}
)
}
}
}