@@ -24,6 +24,7 @@ import (
2424 "github.com/containerd/nerdctl/v2/pkg/infoutil"
2525 "github.com/containerd/nerdctl/v2/pkg/rootlessutil"
2626 "github.com/containerd/nerdctl/v2/pkg/testutil"
27+ "github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil"
2728
2829 "gotest.tools/v3/assert"
2930)
@@ -71,12 +72,14 @@ func TestIPFSAddress(t *testing.T) {
7172}
7273
7374func runIPFSDaemonContainer (t * testing.T , base * testutil.Base ) (ipfsAddress string , done func ()) {
74- name := "test-ipfs-address"
75+ name := "test-ipfs-address-" + testutil . Identifier ( t )
7576 var ipfsaddr string
77+ var addrTest string
7678 if detachedNetNS , _ := rootlessutil .DetachedNetNS (); detachedNetNS != "" {
7779 // detached-netns mode can't use .NetworkSettings.IPAddress, because the daemon and CNI has different network namespaces
7880 base .Cmd ("run" , "-d" , "-p" , "127.0.0.1:5999:5999" , "--name" , name , "--entrypoint=/bin/sh" , testutil .KuboImage , "-c" , "ipfs init && ipfs config Addresses.API /ip4/0.0.0.0/tcp/5999 && ipfs daemon --offline" ).AssertOK ()
7981 ipfsaddr = "/ip4/127.0.0.1/tcp/5999"
82+ addrTest = "127.0.0.1:5999"
8083 } else {
8184 base .Cmd ("run" , "-d" , "--name" , name , "--entrypoint=/bin/sh" , testutil .KuboImage , "-c" , "ipfs init && ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001 && ipfs daemon --offline" ).AssertOK ()
8285 iplines := base .Cmd ("inspect" , name , "-f" , "'{{json .NetworkSettings.IPAddress}}'" ).OutLines ()
@@ -86,10 +89,15 @@ func runIPFSDaemonContainer(t *testing.T, base *testutil.Base) (ipfsAddress stri
8689 t .Logf ("ip address matches=%v" , matches )
8790 assert .Equal (t , len (matches ), 2 )
8891 ipfsaddr = fmt .Sprintf ("/ip4/%s/tcp/5001" , matches [1 ])
92+ addrTest = "127.0.0.1:5001"
8993 }
94+
95+ _ , err := nettestutil .HTTPGet (fmt .Sprintf ("http://%s/api/v0" , addrTest ), 30 , true )
96+ assert .NilError (t , err )
97+
9098 return ipfsaddr , func () {
91- base .Cmd ("kill" , "test-ipfs-address" ).AssertOK ()
92- base .Cmd ("rm" , "test-ipfs-address" ).AssertOK ()
99+ base .Cmd ("kill" , name ).AssertOK ()
100+ base .Cmd ("rm" , name ).AssertOK ()
93101 }
94102}
95103
0 commit comments