testcontainers-go icon indicating copy to clipboard operation
testcontainers-go copied to clipboard

fix: improve get container ip

Open nodece opened this issue 3 years ago • 3 comments

Motivation

Get container ip sometimes empty, I check code and found that we return the inspect.NetworkSettings.IPAddress. If this IP is empty, we should check the inspect.NetworkSettings.Networks, it shouldn't empty.

nodece avatar Jan 09 '22 13:01 nodece

Codecov Report

Merging #396 (900161b) into master (d303350) will decrease coverage by 0.10%. The diff coverage is 50.00%.

:exclamation: Current head 900161b differs from pull request most recent head 97e4b7c. Consider uploading reports for the commit 97e4b7c to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##           master     #396      +/-   ##
==========================================
- Coverage   63.98%   63.88%   -0.11%     
==========================================
  Files          18       18              
  Lines        1108     1113       +5     
==========================================
+ Hits          709      711       +2     
- Misses        295      298       +3     
  Partials      104      104              
Impacted Files Coverage Δ
docker.go 63.96% <50.00%> (-0.24%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d303350...97e4b7c. Read the comment docs.

codecov[bot] avatar Jan 10 '22 08:01 codecov[bot]

Looks like I should make a mock test, do you have any ideas?

nodece avatar Jan 12 '22 02:01 nodece

Have a look at the TestContainerAttachedToNewNetwork test in docker_test.go it already 'covers' what you are trying to avoid. I think it has something to do with whether a container is in the default bridge network or in another non-default network. In the latter case your way of retrieving the IP is the only one working.

prskr avatar Mar 08 '22 20:03 prskr

I'd say this PR has been already solved in #491. Please let us know if we can close it, thanks!

mdelapenya avatar Oct 03 '22 16:10 mdelapenya