-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit test for replicated and app ids
- Loading branch information
Craig O'Donnell
committed
Oct 5, 2023
1 parent
2bca198
commit c1cdcfa
Showing
1 changed file
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
func TestGetReplicatedAndAppIDs(t *testing.T) { | ||
type args struct { | ||
clientset kubernetes.Interface | ||
namespace string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantReplicatedID string | ||
wantAppID string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "get ids from legacy configmap if it exists", | ||
args: args{ | ||
clientset: fake.NewSimpleClientset( | ||
&corev1.ConfigMap{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: GetLegacyReplicatedConfigMapName(), | ||
Namespace: "default", | ||
}, | ||
Data: map[string]string{ | ||
"replicated-sdk-id": "legacy-replicated-id", | ||
"app-id": "legacy-app-id", | ||
}, | ||
}, | ||
), | ||
namespace: "default", | ||
}, | ||
wantReplicatedID: "legacy-replicated-id", | ||
wantAppID: "legacy-app-id", | ||
}, | ||
{ | ||
name: "get ids from deployment uid if legacy configmap does not exist", | ||
args: args{ | ||
clientset: fake.NewSimpleClientset( | ||
&appsv1.Deployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: GetReplicatedDeploymentName(), | ||
Namespace: "default", | ||
UID: "replicated-id", | ||
}, | ||
}, | ||
), | ||
namespace: "default", | ||
}, | ||
wantReplicatedID: "replicated-id", | ||
wantAppID: "replicated-id", | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotReplicatedID, gotAppID, err := GetReplicatedAndAppIDs(tt.args.clientset, tt.args.namespace) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("GetReplicatedAndAppIDs() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if gotReplicatedID != tt.wantReplicatedID { | ||
t.Errorf("GetReplicatedAndAppIDs() got = %v, want %v", gotReplicatedID, tt.wantReplicatedID) | ||
} | ||
if gotAppID != tt.wantAppID { | ||
t.Errorf("GetReplicatedAndAppIDs() got1 = %v, want %v", gotAppID, tt.wantAppID) | ||
} | ||
}) | ||
} | ||
} |