【发布时间】:2018-08-17 20:39:40
【问题描述】:
我一直试图让我们的测试通过我们的 Gitlab CI,但不能。我正在使用 Gitlab 附带的库存管道配置。我所要做的就是提供 gitlab yaml 文件来配置 CI。
这就是我们正在使用的
image: maven:3.5.0-jdk-8-alpine
services:
- postgres:latest
variables:
POSTGRES_DB: my_test_db
POSTGRES_USER: my_test_user
POSTGRES_PASSWORD: ""
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"
ACTIVE_ENV: test
connect:
image: postgres
script:
# official way to provide password to psql: http://www.postgresql.org/docs/9.3/static/libpq-envars.html
- export PGPASSWORD=$POSTGRES_PASSWORD
- psql -h "postgres" -U "$POSTGRES_USER" -d "$POSTGRES_DB" -c "SELECT 'OK' AS status;"
stages:
- test
test:
stage: test
script:
- "mvn -Denvironments=test -B db-migrator:migrate; mvn -Denvironments=test -DACTIVE_ENV=test -B test"
在测试运行之前,一切都完美无缺。然后他们都会出错并显示类似的消息:
383 [main] WARN org.javalite.activeweb.DBSpecHelper - no DB connections are configured, none opened
456 [main] WARN org.javalite.activeweb.DBSpecHelper - no DB connections are configured, none opened
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.528 sec <<< FAILURE! - in app.models.RoleTest
validatePresenceOfUsers(app.models.RoleTest) Time elapsed: 0.071 sec <<< ERROR!
org.javalite.activejdbc.DBException: Failed to retrieve metadata from DB, connection: 'default' is not available
我有一个 database.properties 文件已签入并且仅用于测试(我们的开发和生产环境使用 jndi)。看起来是这样的:
test.driver=org.postgresql.Driver
test.username=my_test_user
test.password=
test.url=jdbc:postgresql://postgres/edv_test
同样,迁移使用所有这些完全相同的配置运行。我只是无法弄清楚为什么测试不会运行。我理解为什么它说没有默认数据库,但我不明白为什么它没有看到测试设置并按预期配置该连接。
【问题讨论】:
-
我建议您在失败之前运行此代码:
System.out.println(AppConfig.activeEnv())- 这将告诉您它作为ACTIVE_ENV获得的价值。 -
啊,比你领先一步。 :) 它们不会格式化,但这些是我在 CI 上打印出来的调试:
env: testload test env properties负载测试调试在我的 DbConfig 块中:if(Configuration.getEnv().equalsIgnoreCase("test")) { System.out.println("load test env properties"); loadConfiguration("src/main/resources/database.properties"); } else { -
不知道为什么要自己加载属性文件
-
好吧,由于通常的原因,我们开始不想检查 database.properties。所以我和我的团队在 gitignore 中设置了我们自己的 database-developer.properties,它有我们自己的本地连接信息。因为我无法在没有属性文件的情况下在 CI 上运行迁移,所以我决定只将 CI 测试配置添加到 database.properties,这就是我使用上述检查的原因。
-
你知道吗,你可以在文件系统上拥有你的连接文件:javalite.io/…
标签: activejdbc activeweb