firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.03k stars 115 forks source link

Handle `host` and `none` networks #1226

Closed PigeonF closed 1 month ago

PigeonF commented 1 month ago

Related to #1225

PigeonF commented 1 month ago

I am not sure how to test connecting to custom networks, since it would require setting up the docker networks in the test. Is there some setup/teardown mechanics for this?

nicDamours commented 1 month ago

@PigeonF You don't have to actually validate that the docker container connects to the proper network. It is out of the scope of this library to test docker itself. However, you can validate that you correctly pass the needed argument to the docker command.

To do so, you can use the return value of the initBashSpy, and use the expect(bashSpy).toHaveBeenLastCalledWith function to assert the content of the command.

for example:

expect(bashSpy).toHaveBeenLastCalledWith(expect.stringContaining("--network someNetwork"), expect.any(String));

Here is an example of this being done in another test

You can also test the Utils.spawn command you use. In order to do that, you would need to edit the initSpawnSpy to also return the spy and then use the toHaveBeenLastCalledWith function, again, to validate the parameters. For example:

expect(spawnSpy).toHaveBeenCalledWith(expect.any(String), "network", "connect", "theNetwork", expect.any(String))
PigeonF commented 1 month ago

Thank you for the help! I have added some tests and have discovered, that my solution is not in fact a solution 🤦 . I have pushed the tests for now, while I am working on a fix.

PigeonF commented 1 month ago

I think this should cover the relevant cases now - though I don't know how well behaved docker is in some of these combinations (i.e. why can we not use --network host --network custom when calling docker container create, but are allowed to do it in two steps with docker network create --network host; docker network connect custom?)

firecow commented 1 month ago

@PigeonF Is this one ready for review? I'm thinking about releasing a new version in the near future.