@@ -2,13 +2,14 @@ package commands
2
2
3
3
import (
4
4
"fmt"
5
+ "os"
6
+ "testing"
7
+ "time"
8
+
5
9
"github.com/argoproj/gitops-engine/pkg/utils/kube"
6
10
"github.com/google/go-cmp/cmp"
7
11
"github.com/google/go-cmp/cmp/cmpopts"
8
12
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
9
- "os"
10
- "testing"
11
- "time"
12
13
13
14
"github.com/argoproj/gitops-engine/pkg/health"
14
15
@@ -22,18 +23,18 @@ import (
22
23
)
23
24
24
25
func Test_getInfos (t * testing.T ) {
25
- testCases := []struct {
26
- name string
27
- infos []string
26
+ testCases := []struct {
27
+ name string
28
+ infos []string
28
29
expectedInfos []* v1alpha1.Info
29
30
}{
30
31
{
31
- name : "empty" ,
32
- infos : []string {},
32
+ name : "empty" ,
33
+ infos : []string {},
33
34
expectedInfos : []* v1alpha1.Info {},
34
35
},
35
36
{
36
- name : "simple key value" ,
37
+ name : "simple key value" ,
37
38
infos : []string {"key1=value1" , "key2=value2" },
38
39
expectedInfos : []* v1alpha1.Info {
39
40
{Name : "key1" , Value : "value1" },
@@ -55,10 +56,10 @@ func Test_getInfos(t *testing.T) {
55
56
func Test_getRefreshType (t * testing.T ) {
56
57
refreshTypeNormal := string (v1alpha1 .RefreshTypeNormal )
57
58
refreshTypeHard := string (v1alpha1 .RefreshTypeHard )
58
- testCases := []struct {
59
- refresh bool
59
+ testCases := []struct {
60
+ refresh bool
60
61
hardRefresh bool
61
- expected * string
62
+ expected * string
62
63
}{
63
64
{false , false , nil },
64
65
{false , true , & refreshTypeHard },
@@ -335,7 +336,7 @@ func Test_groupObjsByKey(t *testing.T) {
335
336
{
336
337
Object : map [string ]interface {}{
337
338
"apiVersion" : "apiextensions.k8s.io/v1" ,
338
- "kind" : "CustomResourceDefinition" ,
339
+ "kind" : "CustomResourceDefinition" ,
339
340
"metadata" : map [string ]interface {}{
340
341
"name" : "certificates.cert-manager.io" ,
341
342
},
@@ -356,7 +357,7 @@ func Test_groupObjsByKey(t *testing.T) {
356
357
{
357
358
Object : map [string ]interface {}{
358
359
"apiVersion" : "apiextensions.k8s.io/v1" ,
359
- "kind" : "CustomResourceDefinition" ,
360
+ "kind" : "CustomResourceDefinition" ,
360
361
"metadata" : map [string ]interface {}{
361
362
"name" : "certificates.cert-manager.io" ,
362
363
},
@@ -365,8 +366,8 @@ func Test_groupObjsByKey(t *testing.T) {
365
366
}
366
367
367
368
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 ],
370
371
}
371
372
372
373
objByKey := groupObjsByKey (localObjs , liveObjs , "default" )
@@ -581,7 +582,7 @@ func TestPrintAppSummaryTable(t *testing.T) {
581
582
582
583
windows := & v1alpha1.SyncWindows {
583
584
{
584
- Kind : "allow" ,
585
+ Kind : "allow" ,
585
586
Schedule : "0 0 * * *" ,
586
587
Duration : "24h" ,
587
588
Applications : []string {
@@ -590,15 +591,15 @@ func TestPrintAppSummaryTable(t *testing.T) {
590
591
ManualSync : true ,
591
592
},
592
593
{
593
- Kind : "deny" ,
594
+ Kind : "deny" ,
594
595
Schedule : "0 0 * * *" ,
595
596
Duration : "24h" ,
596
597
Namespaces : []string {
597
598
"default" ,
598
599
},
599
600
},
600
601
{
601
- Kind : "allow" ,
602
+ Kind : "allow" ,
602
603
Schedule : "0 0 * * *" ,
603
604
Duration : "24h" ,
604
605
Clusters : []string {
@@ -839,11 +840,11 @@ func Test_unset(t *testing.T) {
839
840
Plugin : & v1alpha1.ApplicationSourcePlugin {
840
841
Env : v1alpha1.Env {
841
842
{
842
- Name : "env-1" ,
843
+ Name : "env-1" ,
843
844
Value : "env-value-1" ,
844
845
},
845
846
{
846
- Name : "env-2" ,
847
+ Name : "env-2" ,
847
848
Value : "env-value-2" ,
848
849
},
849
850
},
@@ -942,8 +943,8 @@ func Test_unset(t *testing.T) {
942
943
}
943
944
944
945
func Test_unset_nothingToUnset (t * testing.T ) {
945
- testCases := []struct {
946
- name string
946
+ testCases := []struct {
947
+ name string
947
948
source v1alpha1.ApplicationSource
948
949
}{
949
950
{"kustomize" , v1alpha1.ApplicationSource {Kustomize : & v1alpha1.ApplicationSourceKustomize {}}},
@@ -963,3 +964,70 @@ func Test_unset_nothingToUnset(t *testing.T) {
963
964
})
964
965
}
965
966
}
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\n app-name http://localhost:8080 default prj OutOfSync Healthy <none> <none>\n app-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\n app-name http://localhost:8080 default prj OutOfSync Healthy <none> <none> https://github.com/argoproj/argocd-example-apps guestbook 123\n app-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