mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-05 00:15:44 +00:00
Implements the feature introduced in the design
document added with commit 4bdc1d37
Fixes https://redhat.atlassian.net/browse/RUN-4260
Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
68 lines
1.6 KiB
Go
68 lines
1.6 KiB
Go
package certificates
|
|
|
|
import (
|
|
"crypto/x509"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestDeduplicateCertificates(t *testing.T) {
|
|
certA := &x509.Certificate{Signature: []byte("sig-a")}
|
|
certB := &x509.Certificate{Signature: []byte("sig-b")}
|
|
certC := &x509.Certificate{Signature: []byte("sig-c")}
|
|
|
|
tests := []struct {
|
|
name string
|
|
input []*x509.Certificate
|
|
expected []*x509.Certificate
|
|
}{
|
|
{
|
|
name: "nil slice",
|
|
input: nil,
|
|
expected: nil,
|
|
},
|
|
{
|
|
name: "empty slice",
|
|
input: []*x509.Certificate{},
|
|
expected: nil,
|
|
},
|
|
{
|
|
name: "no duplicates",
|
|
input: []*x509.Certificate{certA, certB, certC},
|
|
expected: []*x509.Certificate{certA, certB, certC},
|
|
},
|
|
{
|
|
name: "with duplicates",
|
|
input: []*x509.Certificate{certA, certB, certA, certC, certB},
|
|
expected: []*x509.Certificate{certA, certB, certC},
|
|
},
|
|
{
|
|
name: "all duplicates",
|
|
input: []*x509.Certificate{certA, certA, certA},
|
|
expected: []*x509.Certificate{certA},
|
|
},
|
|
{
|
|
name: "nil entries are skipped",
|
|
input: []*x509.Certificate{nil, certA, nil, certB},
|
|
expected: []*x509.Certificate{certA, certB},
|
|
},
|
|
{
|
|
name: "nil and duplicate entries",
|
|
input: []*x509.Certificate{nil, certA, certB, nil, certA},
|
|
expected: []*x509.Certificate{certA, certB},
|
|
},
|
|
{
|
|
name: "single certificate",
|
|
input: []*x509.Certificate{certA},
|
|
expected: []*x509.Certificate{certA},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := deduplicateCertificates(tt.input)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|