Skip to content

Commit 683db58

Browse files
committed
updates testcases
Signed-off-by: rashmi_kh <[email protected]>
1 parent 83e188c commit 683db58

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

internal/authentication/tokengetter.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
authenticationv1 "k8s.io/api/authentication/v1"
10+
"k8s.io/apimachinery/pkg/api/errors"
1011
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1112
"k8s.io/apimachinery/pkg/types"
1213
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
@@ -25,7 +26,7 @@ type ServiceAccountNotFoundError struct {
2526
}
2627

2728
func (e *ServiceAccountNotFoundError) Error() string {
28-
return fmt.Sprintf(" Unable to authenticate with Kubernetes cluster using ServiceAccount \"%s\": ServiceAccount \"%s\" not found.", e.ServiceAccountName, e.ServiceAccountName)
29+
return fmt.Sprintf("Unable to authenticate with Kubernetes cluster using ServiceAccount \"%s\": ServiceAccount \"%s\" not found.", e.ServiceAccountName, e.ServiceAccountName)
2930
}
3031

3132
type TokenGetterOption func(*TokenGetter)
@@ -95,8 +96,12 @@ func (t *TokenGetter) getToken(ctx context.Context, key types.NamespacedName) (*
9596
Spec: authenticationv1.TokenRequestSpec{ExpirationSeconds: ptr.To(int64(t.expirationDuration / time.Second))},
9697
}, metav1.CreateOptions{})
9798
if err != nil {
98-
saErr := &ServiceAccountNotFoundError{key.Name}
99-
return nil, saErr
99+
if errors.IsNotFound(err) {
100+
saErr := &ServiceAccountNotFoundError{key.Name}
101+
return nil, saErr
102+
} else {
103+
return nil, err
104+
}
100105
}
101106
return &req.Status, nil
102107
}

internal/authentication/tokengetter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestTokenGetterGet(t *testing.T) {
7171
{"Testing token that expired 10 seconds ago", "test-service-account-3",
7272
"test-namespace-3", "test-token-3", "failed to get token"},
7373
{"Testing error when getting token from fake client", "test-service-account-4",
74-
"test-namespace-4", "error when fetching token", "error when fetching token"},
74+
"test-namespace-4", "error when fetching token.", "error when fetching token"},
7575
}
7676

7777
for _, tc := range tests {

internal/controllers/clusterextension_controller_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ func TestClusterExtensionInstallationFailsWithNoServiceAccount(t *testing.T) {
744744
require.Equal(t, ocv1.BundleMetadata{Name: "prometheus.v1.0.0", Version: "1.0.0"}, clusterExtension.Status.Install.Bundle)
745745

746746
t.Log("By checking the expected installed conditions")
747+
747748
installedCond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1.TypeInstalled)
748749
t.Log("By checking the installed conditions message", installedCond.Message)
749750
require.NotNil(t, installedCond)
@@ -760,8 +761,11 @@ func TestClusterExtensionInstallationFailsWithNoServiceAccount(t *testing.T) {
760761
t.Log("Progressing condition reason", progressingCond.Reason)
761762
//require.Equal(t, metav1.ConditionTrue, progressingCond.Status)
762763
require.Equal(t, ocv1.ReasonFailed, progressingCond.Reason)
764+
failedCond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1.ReasonFailed)
765+
t.Log("By checking the failed conditions message", failedCond.Message)
766+
t.Log("By checking the failed conditions status", failedCond.Status, failedCond.Reason)
763767

764-
//require.NoError(t, cl.DeleteAllOf(ctx, &ocv1.ClusterExtension{}))
768+
require.NoError(t, cl.DeleteAllOf(ctx, &ocv1.ClusterExtension{}))
765769
}
766770

767771
func TestClusterExtensionDeleteFinalizerFails(t *testing.T) {

0 commit comments

Comments
 (0)