mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-05 22:01:37 +02:00
Compare container ports in a smarter way (#1755)
* Compare ports ingoring order and considering protocol defaults Co-authored-by: Felix Kunde <felix-kunde@gmx.de>
This commit is contained in:
co-authored by
Felix Kunde
parent
d8a159ef1a
commit
fb8a6c7a68
@@ -5,6 +5,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
acidv1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
|
||||
fakeacidv1 "github.com/zalando/postgres-operator/pkg/generated/clientset/versioned/fake"
|
||||
@@ -1088,3 +1090,102 @@ func TestValidUsernames(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestComparePorts(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
setA []v1.ContainerPort
|
||||
setB []v1.ContainerPort
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "different ports",
|
||||
setA: []v1.ContainerPort{
|
||||
{
|
||||
Name: "metrics",
|
||||
ContainerPort: 9187,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
|
||||
setB: []v1.ContainerPort{
|
||||
{
|
||||
Name: "http",
|
||||
ContainerPort: 80,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "no difference",
|
||||
setA: []v1.ContainerPort{
|
||||
{
|
||||
Name: "metrics",
|
||||
ContainerPort: 9187,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
setB: []v1.ContainerPort{
|
||||
{
|
||||
Name: "metrics",
|
||||
ContainerPort: 9187,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "same ports, different order",
|
||||
setA: []v1.ContainerPort{
|
||||
{
|
||||
Name: "metrics",
|
||||
ContainerPort: 9187,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Name: "http",
|
||||
ContainerPort: 80,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
setB: []v1.ContainerPort{
|
||||
{
|
||||
Name: "http",
|
||||
ContainerPort: 80,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
{
|
||||
Name: "metrics",
|
||||
ContainerPort: 9187,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "same ports, but one with default protocol",
|
||||
setA: []v1.ContainerPort{
|
||||
{
|
||||
Name: "metrics",
|
||||
ContainerPort: 9187,
|
||||
Protocol: v1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
setB: []v1.ContainerPort{
|
||||
{
|
||||
Name: "metrics",
|
||||
ContainerPort: 9187,
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
got := comparePorts(testCase.setA, testCase.setB)
|
||||
assert.Equal(t, testCase.expected, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user