Skip to content

Commit 62e4973

Browse files
chore: Print application table test (argoproj#9266)
1 parent 0f22d57 commit 62e4973

File tree

1 file changed

+91
-23
lines changed

1 file changed

+91
-23
lines changed

cmd/argocd/commands/app_test.go

+91-23
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package commands
22

33
import (
44
"fmt"
5+
"os"
6+
"testing"
7+
"time"
8+
59
"github.com/argoproj/gitops-engine/pkg/utils/kube"
610
"github.com/google/go-cmp/cmp"
711
"github.com/google/go-cmp/cmp/cmpopts"
812
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
9-
"os"
10-
"testing"
11-
"time"
1213

1314
"github.com/argoproj/gitops-engine/pkg/health"
1415

@@ -22,18 +23,18 @@ import (
2223
)
2324

2425
func Test_getInfos(t *testing.T) {
25-
testCases := []struct{
26-
name string
27-
infos []string
26+
testCases := []struct {
27+
name string
28+
infos []string
2829
expectedInfos []*v1alpha1.Info
2930
}{
3031
{
31-
name: "empty",
32-
infos: []string{},
32+
name: "empty",
33+
infos: []string{},
3334
expectedInfos: []*v1alpha1.Info{},
3435
},
3536
{
36-
name: "simple key value",
37+
name: "simple key value",
3738
infos: []string{"key1=value1", "key2=value2"},
3839
expectedInfos: []*v1alpha1.Info{
3940
{Name: "key1", Value: "value1"},
@@ -55,10 +56,10 @@ func Test_getInfos(t *testing.T) {
5556
func Test_getRefreshType(t *testing.T) {
5657
refreshTypeNormal := string(v1alpha1.RefreshTypeNormal)
5758
refreshTypeHard := string(v1alpha1.RefreshTypeHard)
58-
testCases := []struct{
59-
refresh bool
59+
testCases := []struct {
60+
refresh bool
6061
hardRefresh bool
61-
expected *string
62+
expected *string
6263
}{
6364
{false, false, nil},
6465
{false, true, &refreshTypeHard},
@@ -335,7 +336,7 @@ func Test_groupObjsByKey(t *testing.T) {
335336
{
336337
Object: map[string]interface{}{
337338
"apiVersion": "apiextensions.k8s.io/v1",
338-
"kind": "CustomResourceDefinition",
339+
"kind": "CustomResourceDefinition",
339340
"metadata": map[string]interface{}{
340341
"name": "certificates.cert-manager.io",
341342
},
@@ -356,7 +357,7 @@ func Test_groupObjsByKey(t *testing.T) {
356357
{
357358
Object: map[string]interface{}{
358359
"apiVersion": "apiextensions.k8s.io/v1",
359-
"kind": "CustomResourceDefinition",
360+
"kind": "CustomResourceDefinition",
360361
"metadata": map[string]interface{}{
361362
"name": "certificates.cert-manager.io",
362363
},
@@ -365,8 +366,8 @@ func Test_groupObjsByKey(t *testing.T) {
365366
}
366367

367368
expected := map[kube.ResourceKey]*unstructured.Unstructured{
368-
kube.ResourceKey{Group:"", Kind:"Pod", Namespace:"default", Name:"pod-name"}: localObjs[0],
369-
kube.ResourceKey{Group:"apiextensions.k8s.io", Kind:"CustomResourceDefinition", Namespace:"", Name:"certificates.cert-manager.io"}: localObjs[1],
369+
kube.ResourceKey{Group: "", Kind: "Pod", Namespace: "default", Name: "pod-name"}: localObjs[0],
370+
kube.ResourceKey{Group: "apiextensions.k8s.io", Kind: "CustomResourceDefinition", Namespace: "", Name: "certificates.cert-manager.io"}: localObjs[1],
370371
}
371372

372373
objByKey := groupObjsByKey(localObjs, liveObjs, "default")
@@ -581,7 +582,7 @@ func TestPrintAppSummaryTable(t *testing.T) {
581582

582583
windows := &v1alpha1.SyncWindows{
583584
{
584-
Kind: "allow",
585+
Kind: "allow",
585586
Schedule: "0 0 * * *",
586587
Duration: "24h",
587588
Applications: []string{
@@ -590,15 +591,15 @@ func TestPrintAppSummaryTable(t *testing.T) {
590591
ManualSync: true,
591592
},
592593
{
593-
Kind: "deny",
594+
Kind: "deny",
594595
Schedule: "0 0 * * *",
595596
Duration: "24h",
596597
Namespaces: []string{
597598
"default",
598599
},
599600
},
600601
{
601-
Kind: "allow",
602+
Kind: "allow",
602603
Schedule: "0 0 * * *",
603604
Duration: "24h",
604605
Clusters: []string{
@@ -839,11 +840,11 @@ func Test_unset(t *testing.T) {
839840
Plugin: &v1alpha1.ApplicationSourcePlugin{
840841
Env: v1alpha1.Env{
841842
{
842-
Name: "env-1",
843+
Name: "env-1",
843844
Value: "env-value-1",
844845
},
845846
{
846-
Name: "env-2",
847+
Name: "env-2",
847848
Value: "env-value-2",
848849
},
849850
},
@@ -942,8 +943,8 @@ func Test_unset(t *testing.T) {
942943
}
943944

944945
func Test_unset_nothingToUnset(t *testing.T) {
945-
testCases := []struct{
946-
name string
946+
testCases := []struct {
947+
name string
947948
source v1alpha1.ApplicationSource
948949
}{
949950
{"kustomize", v1alpha1.ApplicationSource{Kustomize: &v1alpha1.ApplicationSourceKustomize{}}},
@@ -963,3 +964,70 @@ func Test_unset_nothingToUnset(t *testing.T) {
963964
})
964965
}
965966
}
967+
968+
func TestPrintApplicationTableNotWide(t *testing.T) {
969+
output, err := captureOutput(func() error {
970+
app := &v1alpha1.Application{
971+
ObjectMeta: metav1.ObjectMeta{
972+
Name: "app-name",
973+
},
974+
Spec: v1alpha1.ApplicationSpec{
975+
Destination: v1alpha1.ApplicationDestination{
976+
Server: "http://localhost:8080",
977+
Namespace: "default",
978+
},
979+
Project: "prj",
980+
},
981+
Status: v1alpha1.ApplicationStatus{
982+
Sync: v1alpha1.SyncStatus{
983+
Status: "OutOfSync",
984+
},
985+
Health: v1alpha1.HealthStatus{
986+
Status: "Healthy",
987+
},
988+
},
989+
}
990+
output := "table"
991+
printApplicationTable([]v1alpha1.Application{*app, *app}, &output)
992+
return nil
993+
})
994+
assert.NoError(t, err)
995+
expectation := "NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS\napp-name http://localhost:8080 default prj OutOfSync Healthy <none> <none>\napp-name http://localhost:8080 default prj OutOfSync Healthy <none> <none>\n"
996+
assert.Equal(t, output, expectation)
997+
}
998+
999+
func TestPrintApplicationTableWide(t *testing.T) {
1000+
output, err := captureOutput(func() error {
1001+
app := &v1alpha1.Application{
1002+
ObjectMeta: metav1.ObjectMeta{
1003+
Name: "app-name",
1004+
},
1005+
Spec: v1alpha1.ApplicationSpec{
1006+
Destination: v1alpha1.ApplicationDestination{
1007+
Server: "http://localhost:8080",
1008+
Namespace: "default",
1009+
},
1010+
Source: v1alpha1.ApplicationSource{
1011+
RepoURL: "https://github.com/argoproj/argocd-example-apps",
1012+
Path: "guestbook",
1013+
TargetRevision: "123",
1014+
},
1015+
Project: "prj",
1016+
},
1017+
Status: v1alpha1.ApplicationStatus{
1018+
Sync: v1alpha1.SyncStatus{
1019+
Status: "OutOfSync",
1020+
},
1021+
Health: v1alpha1.HealthStatus{
1022+
Status: "Healthy",
1023+
},
1024+
},
1025+
}
1026+
output := "wide"
1027+
printApplicationTable([]v1alpha1.Application{*app, *app}, &output)
1028+
return nil
1029+
})
1030+
assert.NoError(t, err)
1031+
expectation := "NAME CLUSTER NAMESPACE PROJECT STATUS HEALTH SYNCPOLICY CONDITIONS REPO PATH TARGET\napp-name http://localhost:8080 default prj OutOfSync Healthy <none> <none> https://github.com/argoproj/argocd-example-apps guestbook 123\napp-name http://localhost:8080 default prj OutOfSync Healthy <none> <none> https://github.com/argoproj/argocd-example-apps guestbook 123\n"
1032+
assert.Equal(t, output, expectation)
1033+
}

0 commit comments

Comments
 (0)