@@ -27,7 +27,9 @@ import (
2727 api "github.com/moby/moby/api/types/image"
2828 "github.com/moby/moby/api/types/storage"
2929 "github.com/moby/moby/client"
30+ ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3031
32+ "github.com/google/go-cmp/cmp"
3133 "github.com/google/go-containerregistry/pkg/name"
3234 "github.com/google/go-containerregistry/pkg/v1/compare"
3335 "github.com/google/go-containerregistry/pkg/v1/tarball"
@@ -289,6 +291,45 @@ func TestImageFileBuffered(t *testing.T) {
289291 })
290292}
291293
294+ func TestImageConfigExposedPorts (t * testing.T ) {
295+ want := map [string ]struct {}{
296+ "80/tcp" : {},
297+ "443/tcp" : {},
298+ "53/udp" : {},
299+ }
300+
301+ resp := inspectResp
302+ resp .Config = & specs.DockerOCIImageConfig {
303+ ImageConfig : ocispec.ImageConfig {
304+ ExposedPorts : want ,
305+ },
306+ }
307+
308+ mc := & MockClient {
309+ path : imagePath ,
310+ inspectResp : resp ,
311+ }
312+
313+ tag , err := name .NewTag ("unused" , name .WeakValidation )
314+ if err != nil {
315+ t .Fatalf ("NewTag: %v" , err )
316+ }
317+
318+ dmn , err := Image (tag , WithClient (mc ), WithUnbufferedOpener ())
319+ if err != nil {
320+ t .Fatalf ("Image(): %v" , err )
321+ }
322+
323+ cf , err := dmn .ConfigFile ()
324+ if err != nil {
325+ t .Fatalf ("ConfigFile(): %v" , err )
326+ }
327+
328+ if diff := cmp .Diff (want , cf .Config .ExposedPorts ); diff != "" {
329+ t .Errorf ("ExposedPorts mismatch (-want +got):\n %s" , diff )
330+ }
331+ }
332+
292333func TestImageDefaultClient (t * testing.T ) {
293334 wantErr := fmt .Errorf ("bad client" )
294335 defaultClient = func () (Client , error ) {
0 commit comments