@@ -4,14 +4,14 @@ import (
4
4
"fmt"
5
5
"os"
6
6
"slices"
7
- "sort"
8
7
"strconv"
9
8
"strings"
10
9
"testing"
11
10
"time"
12
11
13
12
"go.uber.org/mock/gomock"
14
13
14
+ "github.com/google/go-cmp/cmp"
15
15
"github.com/google/uuid"
16
16
"github.com/ory/dockertest/v3"
17
17
"github.com/ory/dockertest/v3/docker"
@@ -307,7 +307,6 @@ func TestContainersHandler(t *testing.T) {
307
307
})
308
308
}
309
309
310
- // TestDockerPortBinding tests the port binding handling in convertDockerInspect
311
310
func TestDockerPortBinding (t * testing.T ) {
312
311
t .Parallel ()
313
312
@@ -421,7 +420,6 @@ func TestDockerPortBinding(t *testing.T) {
421
420
t .Run (tc .name , func (t * testing.T ) {
422
421
t .Parallel ()
423
422
424
- // Create a sample docker inspection result
425
423
dockerData := dockerInspect {
426
424
ID : "test-container" ,
427
425
Created : time .Now (),
@@ -436,34 +434,11 @@ func TestDockerPortBinding(t *testing.T) {
436
434
},
437
435
}
438
436
439
- // Process the docker data
440
437
container , warns := convertDockerInspect (dockerData )
441
-
442
- // Verify the ports
443
- assert .Len (t , container .Ports , len (tc .expectedPorts ), "wrong number of ports" )
444
- assert .Len (t , warns , tc .expectedWarns , "wrong number of warnings" )
445
-
446
- // Sort ports for consistent comparison (order may vary)
447
- sort .Slice (container .Ports , func (i , j int ) bool {
448
- if container .Ports [i ].Network == container .Ports [j ].Network {
449
- return container .Ports [i ].Port < container .Ports [j ].Port
450
- }
451
- return container .Ports [i ].Network < container .Ports [j ].Network
452
- })
453
- sort .Slice (tc .expectedPorts , func (i , j int ) bool {
454
- if tc .expectedPorts [i ].Network == tc .expectedPorts [j ].Network {
455
- return tc .expectedPorts [i ].Port < tc .expectedPorts [j ].Port
456
- }
457
- return tc .expectedPorts [i ].Network < tc .expectedPorts [j ].Network
458
- })
459
-
460
- // Compare ports
461
- for i , expected := range tc .expectedPorts {
462
- if i < len (container .Ports ) {
463
- assert .Equal (t , expected .Network , container .Ports [i ].Network , "network mismatch" )
464
- assert .Equal (t , expected .Port , container .Ports [i ].Port , "port mismatch" )
465
- }
438
+ if diff := cmp .Diff (tc .expectedPorts , container .Ports ); diff != "" {
439
+ assert .Failf (t , "port mismatch" , "(-want +got):\n %s" , diff )
466
440
}
441
+ assert .Len (t , warns , tc .expectedWarns , "wrong number of warnings" )
467
442
})
468
443
}
469
444
}
0 commit comments