Skip to content

Commit

Permalink
Adding comparision of duration value in test
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamcoc committed Jun 10, 2023
1 parent 2e5da3b commit 3b1dfb6
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pkg/pki/certmanagerpki/certmanager_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ import (

"github.com/banzaicloud/koperator/api/v1alpha1"
"github.com/banzaicloud/koperator/pkg/errorfactory"
"github.com/banzaicloud/koperator/pkg/util"
certutil "github.com/banzaicloud/koperator/pkg/util/cert"
)

var certDur int32 = 7200

func newMockUser() *v1alpha1.KafkaUser {
user := &v1alpha1.KafkaUser{}
user.Name = "test-user"
Expand Down Expand Up @@ -106,12 +107,24 @@ func TestReconcileUserCertificate(t *testing.T) {

// Test cert duration
user = newMockUser()
user.Spec.ExpirationSeconds = util.Int32Pointer(7200)
user.Spec.ExpirationSeconds = &certDur

if _, err := manager.ReconcileUserCertificate(ctx, user, scheme.Scheme, clusterDomain); err != nil {
userCert, err := manager.ReconcileUserCertificate(ctx, user, scheme.Scheme, clusterDomain)
if err != nil {
t.Error("Expected no error, got:", err)
}

decodedCert, err := certutil.DecodeCertificate(userCert.Certificate)
if err != nil {
t.Error("Expected no error, got:", err)
}

// user.Spec.ExpirationSeconds = util.Int32Pointer(2300)
certDuration := decodedCert.NotAfter.Sub(decodedCert.NotBefore).Seconds()
if *user.Spec.ExpirationSeconds != int32(certDuration) {
t.Errorf("Expected cert duration is not the same as the actual cert duration, expected: %d, got: %d", *user.Spec.ExpirationSeconds, int32(certDuration))
}

// Test error conditions
manager, err = newMock(newMockCluster())
if err != nil {
Expand Down

0 comments on commit 3b1dfb6

Please sign in to comment.