18
Апр
2018

Запуск автотестов с TestContainer в GitLab

Не запускаются тесты с TestContainer в GitLab.

.gitlab-ci.yml :

image: docker:latest
services:
  - docker:dind

variables:
  DOCKER_DRIVER: overlay
  M2_REPO: .m2/repository

stages:
  - test

test:
  image: maven:3-jdk-8
  stage: test
  tags:
    - docker
  script: |
    mvn verify test
  artifacts:
    paths:
    - core.*
    - hs_err_pid*.log

test:

import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.PostgreSQLContainer;
import static org.junit.Assert.assertNotNull;
public class TestContainerExampleTest {
    @Rule
    public PostgreSQLContainer postgres = new PostgreSQLContainer();
    @Test
    public void test() {assertNotNull(postgres.getJdbcUrl());}
}

Ошибки:

Apr 18, 2018 6:05:21 AM org.testcontainers.dockerclient.EnvironmentAndSystemPropertyClientProviderStrategy test
ERROR: ping failed with configuration Environment variables, system properties and defaults. Resolved: 
    dockerHost=unix:///var/run/docker.sock
    apiVersion='{UNKNOWN_VERSION}'
    registryUrl='https://index.docker.io/v1/'
    registryUsername='root'
    registryPassword='null'
    registryEmail='null'
    dockerConfig='DefaultDockerClientConfig[dockerHost=unix:///var/run/docker.sock,registryUsername=root,registryPassword=<null>,registryEmail=<null>,registryUrl=https://index.docker.io/v1/,dockerConfig=/root/.docker,sslConfig=<null>,apiVersion={UNKNOWN_VERSION}]'
 due to org.rnorth.ducttape.TimeoutException: Timeout waiting for result with exception
org.rnorth.ducttape.TimeoutException: Timeout waiting for result with exception
    at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:51)
<blablabla...>
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.testcontainers.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: connect(..) failed: No such file or directory: /var/run/docker.sock
    at org.testcontainers.shaded.io.netty.channel.unix.Errors.throwConnectException(Errors.java:107)
<blablabla...>
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: connect(..) failed: No such file or directory
    ... 23 more

Apr 18, 2018 6:05:21 AM org.testcontainers.dockerclient.DockerClientProviderStrategy lambda$getFirstValidStrategy$2
ERROR: Could not find a valid Docker environment. Please check configuration. Attempted configurations were:
Apr 18, 2018 6:05:21 AM org.testcontainers.dockerclient.DockerClientProviderStrategy lambda$getFirstValidStrategy$2
ERROR:     EnvironmentAndSystemPropertyClientProviderStrategy: failed with exception InvalidConfigurationException (ping failed)
Apr 18, 2018 6:05:21 AM org.testcontainers.dockerclient.DockerClientProviderStrategy lambda$getFirstValidStrategy$2
ERROR:     UnixSocketClientProviderStrategy: failed with exception InvalidConfigurationException (ping failed). Root cause NoSuchFileException (/var/run/docker.sock)
Apr 18, 2018 6:05:21 AM org.testcontainers.dockerclient.DockerClientProviderStrategy lambda$getFirstValidStrategy$2
ERROR: As no valid configuration was found, execution cannot continue
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 10.693 sec <<< FAILURE!
test(ru.bcs.userstorage.online.integration.provider.TestContainerExampleTest)  Time elapsed: 0.005 sec  <<< ERROR!
java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
    at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$2(DockerClientProviderStrategy.java:146)
<blablabla...>

Results :

Tests in error: 
  test(ru.bcs.userstorage.online.integration.provider.TestContainerExampleTest): Could not find a valid Docker environment. Please see logs and check configuration

Tests run: 52, Failures: 0, Errors: 1, Skipped: 4

Репозиторий в GitLab

Локально всё работает. Не запускается именно на GitLab, что-то не так с раннером. Он не умеет в докере докер создавать. Подскажите, можно ли каким-то расшаренным раннером в GitLab запустить такой тест, и вообще от чего это зависит?

Источник: https://ru.stackoverflow.com/questions/815792/%D0%97%D0%B0%D0%BF%D1%83%D1%81%D0%BA-%D0%B0%D0%B2%D1%82%D0%BE%D1%82%D0%B5%D1%81%D1%82%D0%BE%D0%B2-%D1%81-testcontainer-%D0%B2-gitlab

Тебе может это понравится...

Добавить комментарий