Skip to content

Bug: Incompatible with Development Containers #1206

@finite8

Description

@finite8

Describe the bug
When gnomock is used to launch a container when run inside of a devcontainer it fails to start. This is because of how it initializes and checks the state of the launched container by using the resulting ip address of the container. When being executed from within a devcontainer, the container is a peer to the other containers being launched, not a child like it is when run directly on the host.

To Reproduce

  • Take an existing test that uses gnomock and run it inside of a development container
  • Test will fail as the launch will not be able to reach the container by IP address

Expected behavior

  • The container should launch

Additional context
My current workaround is in this fork here: master...finite8:gnomock:master
The reason why the init phase was not acceptable is that it was unable to change the actual host details prior to the other checks occurring. This means that no matter what "host" it is set to, the resulting container cannot be adressed. This change allows it to be worked around by invoking additional setup options when being run inside of a container. For example:

gnomock.WithPostCreate(func(ctx context.Context, c *gnomock.Container) error {
				cmd := exec.Command("docker", "network", "connect", "devnet", "kafka")
				cmd.Env = append(cmd.Env, "PATH="+os.Getenv("PATH"))
				fmt.Println(cmd.Env)
				c.Host = "kafka"
				return cmd.Run()
			})

Because this modifies the original gnomock.Container instance, with the host now specified and the network now created, it allows the dev container to correctly communicate with the "kafka" container by name and it operates as expected. Without it, it fails during initialization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions