Skip to content

Instantly share code, notes, and snippets.

@huksley
Last active September 1, 2024 15:53
Show Gist options
  • Save huksley/4f3d2455d65e154d4fb296fca4e49897 to your computer and use it in GitHub Desktop.
Save huksley/4f3d2455d65e154d4fb296fca4e49897 to your computer and use it in GitHub Desktop.
Test container withLogConsumer does not stream any logs
const { GenericContainer } = require("testcontainers");
const container = new GenericContainer("ubuntu:latest")
.withLogConsumer(consumer => {
consumer.on("data", data => {
console.log("LOG", data.toString());
});
consumer.on("err", data => {
console.log("ERR", data.toString());
});
})
.withCommand(["/bin/bash", "-c", "while true; do sleep 1; done"])
.withUser("ubuntu")
.start()
.then(async container => {
const result = await container.exec(["echo", "1"]);
console.log("RESULT", result);
container.stop();
});
@huksley
Copy link
Author

huksley commented Sep 1, 2024

  testcontainers [DEBUG] Checking container runtime strategy "TestcontainersHostStrategy"... +0ms
  testcontainers [DEBUG] Container runtime strategy "TestcontainersHostStrategy" is not applicable +0ms
  testcontainers [DEBUG] Checking container runtime strategy "ConfigurationStrategy"... +0ms
  testcontainers [DEBUG] Container runtime strategy "ConfigurationStrategy" is not applicable +1ms
  testcontainers [DEBUG] Checking container runtime strategy "UnixSocketStrategy"... +0ms
  testcontainers [TRACE] Fetching Docker info... +0ms
  testcontainers [TRACE] Fetching remote container runtime socket path... +14ms
  testcontainers [TRACE] Resolving host... +0ms
  testcontainers [TRACE] Fetching Compose info... +1ms
  testcontainers [TRACE] Looking up host IPs... +563ms
  testcontainers [TRACE] Initialising clients... +4ms
  testcontainers [TRACE] Container runtime info:
  testcontainers {
  testcontainers   "node": {
  testcontainers     "version": "v18.18.2",
  testcontainers     "architecture": "arm64",
  testcontainers     "platform": "darwin"
  testcontainers   },
  testcontainers   "containerRuntime": {
  testcontainers     "host": "localhost",
  testcontainers     "hostIps": [
  testcontainers       {
  testcontainers         "address": "::1",
  testcontainers         "family": 6
  testcontainers       },
  testcontainers       {
  testcontainers         "address": "127.0.0.1",
  testcontainers         "family": 4
  testcontainers       }
  testcontainers     ],
  testcontainers     "remoteSocketPath": "/var/run/docker.sock",
  testcontainers     "indexServerAddress": "https://index.docker.io/v1/",
  testcontainers     "serverVersion": "26.1.1",
  testcontainers     "operatingSystem": "Docker Desktop",
  testcontainers     "operatingSystemType": "linux",
  testcontainers     "architecture": "aarch64",
  testcontainers     "cpus": 12,
  testcontainers     "memory": 8221421568,
  testcontainers     "runtimes": [
  testcontainers       "io.containerd.runc.v2",
  testcontainers       "runc"
  testcontainers     ],
  testcontainers     "labels": [
  testcontainers       "com.docker.desktop.address=unix:///Users/user/Library/Containers/com.docker.docker/Data/docker-cli.sock"
  testcontainers     ]
  testcontainers   },
  testcontainers   "compose": {
  testcontainers     "version": "2.27.0-desktop.2",
  testcontainers     "compatability": "v2"
  testcontainers   }
  testcontainers } +1ms
  testcontainers [DEBUG] Container runtime strategy "UnixSocketStrategy" works +0ms
  testcontainers [DEBUG] Checking if image exists "ubuntu:latest"... +1ms
  testcontainers [DEBUG] Checked if image exists "ubuntu:latest" +6ms
  testcontainers [DEBUG] Image "ubuntu:latest" already exists +0ms
  testcontainers [DEBUG] Acquiring lock file "/var/folders/1m/y_yy2rmx45vg92lw172ykrgw0000gn/T/testcontainers-node.lock"... +1ms
  testcontainers [DEBUG] Acquired lock file "/var/folders/1m/y_yy2rmx45vg92lw172ykrgw0000gn/T/testcontainers-node.lock" +3ms
  testcontainers [DEBUG] Listing containers... +0ms
  testcontainers [DEBUG] Listed containers +6ms
  testcontainers [DEBUG] Reusing existing Reaper for session "fda893052638"... +0ms
  testcontainers [DEBUG] [72780881cea5] Connecting to Reaper (attempt 1) on "localhost:55005"... +0ms
  testcontainers [DEBUG] [72780881cea5] Connected to Reaper +1ms
  testcontainers [DEBUG] Releasing lock file "/var/folders/1m/y_yy2rmx45vg92lw172ykrgw0000gn/T/testcontainers-node.lock"... +0ms
  testcontainers [DEBUG] Released lock file "/var/folders/1m/y_yy2rmx45vg92lw172ykrgw0000gn/T/testcontainers-node.lock" +0ms
  testcontainers [DEBUG] Creating container for image "ubuntu:latest"... +0ms
  testcontainers [DEBUG] [2b10d061972a] Created container for image "ubuntu:latest" +27ms
  testcontainers [INFO] [2b10d061972a] Starting container for image "ubuntu:latest"... +0ms
  testcontainers [DEBUG] [2b10d061972a] Starting container... +0ms
  testcontainers [DEBUG] [2b10d061972a] Started container +76ms
  testcontainers [INFO] [2b10d061972a] Started container for image "ubuntu:latest" +0ms
  testcontainers [DEBUG] [2b10d061972a] Inspecting container... +1ms
  testcontainers [DEBUG] [2b10d061972a] Inspected container +2ms
  testcontainers [DEBUG] [2b10d061972a] Fetching container logs... +0ms
  testcontainers [DEBUG] [2b10d061972a] Demuxing stream... +2ms
  testcontainers [DEBUG] [2b10d061972a] Demuxed stream +0ms
  testcontainers [DEBUG] [2b10d061972a] Fetched container logs +0ms
  testcontainers [DEBUG] [2b10d061972a] Fetching container logs... +0ms
  testcontainers [DEBUG] [2b10d061972a] Demuxing stream... +1ms
  testcontainers [DEBUG] [2b10d061972a] Demuxed stream +1ms
  testcontainers [DEBUG] [2b10d061972a] Fetched container logs +0ms
  testcontainers [DEBUG] [2b10d061972a] Waiting for container to be ready... +0ms
  testcontainers [DEBUG] [2b10d061972a] Host port wait strategy complete +0ms
  testcontainers [INFO] [2b10d061972a] Container is ready +0ms
  testcontainers [DEBUG] [2b10d061972a] Executing command "echo 1"... +0ms
  testcontainers [DEBUG] [2b10d061972a] Executed command "echo 1"... +27ms
RESULT { output: '1\n', exitCode: 0 }
  testcontainers [INFO] [2b10d061972a] Stopping container... +1ms
  testcontainers [DEBUG] [2b10d061972a] Stopping container... +0ms
  testcontainers [DEBUG] [2b10d061972a] Stopped container +67ms
  testcontainers [DEBUG] [2b10d061972a] Removing container... +0ms
  testcontainers [DEBUG] [2b10d061972a] Removed container +6ms
  testcontainers [INFO] [2b10d061972a] Stopped container +0ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment