func TestCertCompleter_reconcileSecret_emptySecret(t *testing.T) {
	ctrl := CertCompleter{
		Log: zap.New(),
	}
	secret := &corev1.Secret{
		TypeMeta: metav1.TypeMeta{
			Kind:       "secret",
			APIVersion: corev1.SchemeGroupVersion.String(),
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:      "test-secret",
			Namespace: "test-namespace",
		},
		Type: corev1.SecretTypeTLS,
		Data: map[string][]byte{
			"ca.crt":  nil,
			"tls.crt": nil,
		},
	}
	updatedSecret, err := ctrl.reconcileSecret(secret)
	assert.NoError(t, err)
	assert.Empty(t, updatedSecret)
}
It should ignore empty TLS secrets.
package controllers
import (
	"github.com/stretchr/testify/assert"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"sigs.k8s.io/controller-runtime/pkg/log/zap"
	"strings"
	"testing"
)
func TestCertCompleter_reconcileSecret_certChain(t *testing.T) {
	ctrl := CertCompleter{
		Log: zap.New(),
	}
	secret := &corev1.Secret{
		TypeMeta: metav1.TypeMeta{
			Kind:       "secret",
			APIVersion: corev1.SchemeGroupVersion.String(),
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:      "test-secret",
			Namespace: "test-namespace",
		},
		Type: corev1.SecretTypeTLS,
		Data: map[string][]byte{
			"ca.crt":  nil,
			"tls.crt": []byte(strings.Join(certs, "")),
		},
	}
	updatedSecret, err := ctrl.reconcileSecret(secret)
	assert.NoError(t, err)
	assert.NotEmpty(t, updatedSecret)
	assert.Equal(t, certs[len(certs)-1], string(updatedSecret.Data["ca.crt"]))
	assert.Equal(t, updatedSecret.Data["tls.crt"], updatedSecret.Data["tls.crt"])
}
func TestCertCompleter_reconcileSecret_singleCert(t *testing.T) {
	ctrl := CertCompleter{
		Log: zap.New(),
	}
	secret := &corev1.Secret{
		TypeMeta: metav1.TypeMeta{
			Kind:       "secret",
			APIVersion: corev1.SchemeGroupVersion.String(),
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:      "test-secret",
			Namespace: "test-namespace",
		},
		Type: corev1.SecretTypeTLS,
		Data: map[string][]byte{
			"ca.crt":  nil,
			"tls.crt": []byte(certs[0]),
		},
	}
	updatedSecret, err := ctrl.reconcileSecret(secret)
	assert.NoError(t, err)
	assert.NotEmpty(t, updatedSecret)
	assert.Equal(t, certs[0], string(updatedSecret.Data["ca.crt"]))
	assert.Equal(t, updatedSecret.Data["tls.crt"], updatedSecret.Data["tls.crt"])
}
func TestCertCompleter_reconcileSecret_nonTLS(t *testing.T) {
	ctrl := CertCompleter{
		Log: zap.New(),
	}
	secret := &corev1.Secret{
		TypeMeta: metav1.TypeMeta{
			Kind:       "secret",
			APIVersion: corev1.SchemeGroupVersion.String(),
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:      "test-secret",
			Namespace: "test-namespace",
		},
		Type: corev1.SecretTypeOpaque,
		Data: map[string][]byte{
			"ca.crt":  nil,
			"tls.crt": []byte(strings.Join(certs, "")),
		},
	}
	updatedSecret, err := ctrl.reconcileSecret(secret)
	assert.NoError(t, err)
	assert.Empty(t, updatedSecret)
}
func TestCertCompleter_reconcileSecret_completeSecret(t *testing.T) {
	ctrl := CertCompleter{
		Log: zap.New(),
	}
	secret := &corev1.Secret{
		TypeMeta: metav1.TypeMeta{
			Kind:       "secret",
			APIVersion: corev1.SchemeGroupVersion.String(),
		},
		ObjectMeta: metav1.ObjectMeta{
			Name:      "test-secret",
			Namespace: "test-namespace",
		},
		Type: corev1.SecretTypeTLS,
		Data: map[string][]byte{
			"ca.crt":  []byte(certs[len(certs)-1]),
			"tls.crt": []byte(strings.Join(certs, "")),
		},
	}
	updatedSecret, err := ctrl.reconcileSecret(secret)
	assert.NoError(t, err)
	assert.Empty(t, updatedSecret)
}