Unverified Commit 62e49739 authored by pasha-codefresh's avatar pasha-codefresh Committed by GitHub
Browse files

chore: Print application table test (#9266)

parent 0f22d57a
Showing with 91 additions and 23 deletions
+91 -23
......@@ -2,13 +2,14 @@ package commands
import (
"fmt"
"os"
"testing"
"time"
"github.com/argoproj/gitops-engine/pkg/utils/kube"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"os"
"testing"
"time"
"github.com/argoproj/gitops-engine/pkg/health"
......@@ -22,7 +23,7 @@ import (
)
func Test_getInfos(t *testing.T) {
testCases := []struct{
testCases := []struct {
name string
infos []string
expectedInfos []*v1alpha1.Info
......@@ -55,7 +56,7 @@ func Test_getInfos(t *testing.T) {
func Test_getRefreshType(t *testing.T) {
refreshTypeNormal := string(v1alpha1.RefreshTypeNormal)
refreshTypeHard := string(v1alpha1.RefreshTypeHard)
testCases := []struct{
testCases := []struct {
refresh bool
hardRefresh bool
expected *string
......@@ -365,8 +366,8 @@ func Test_groupObjsByKey(t *testing.T) {
}
expected := map[kube.ResourceKey]*unstructured.Unstructured{
kube.ResourceKey{Group:"", Kind:"Pod", Namespace:"default", Name:"pod-name"}: localObjs[0],
kube.ResourceKey{Group:"apiextensions.k8s.io", Kind:"CustomResourceDefinition", Namespace:"", Name:"certificates.cert-manager.io"}: localObjs[1],
kube.ResourceKey{Group: "", Kind: "Pod", Namespace: "default", Name: "pod-name"}: localObjs[0],
kube.ResourceKey{Group: "apiextensions.k8s.io", Kind: "CustomResourceDefinition", Namespace: "", Name: "certificates.cert-manager.io"}: localObjs[1],
}
objByKey := groupObjsByKey(localObjs, liveObjs, "default")
......@@ -942,7 +943,7 @@ func Test_unset(t *testing.T) {
}
func Test_unset_nothingToUnset(t *testing.T) {
testCases := []struct{
testCases := []struct {
name string
source v1alpha1.ApplicationSource
}{
......@@ -963,3 +964,70 @@ func Test_unset_nothingToUnset(t *testing.T) {
})
}
}
func TestPrintApplicationTableNotWide(t *testing.T) {
output, err := captureOutput(func() error {
app := &v1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "app-name",
},
Spec: v1alpha1.ApplicationSpec{
Destination: v1alpha1.ApplicationDestination{
Server: "http://localhost:8080",
Namespace: "default",
},
Project: "prj",
},
Status: v1alpha1.ApplicationStatus{
Sync: v1alpha1.SyncStatus{
Status: "OutOfSync",
},
Health: v1alpha1.HealthStatus{
Status: "Healthy",
},
},
}
output := "table"
printApplicationTable([]v1alpha1.Application{*app, *app}, &output)
return nil
})
assert.NoError(t, err)
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"
assert.Equal(t, output, expectation)
}
func TestPrintApplicationTableWide(t *testing.T) {
output, err := captureOutput(func() error {
app := &v1alpha1.Application{
ObjectMeta: metav1.ObjectMeta{
Name: "app-name",
},
Spec: v1alpha1.ApplicationSpec{
Destination: v1alpha1.ApplicationDestination{
Server: "http://localhost:8080",
Namespace: "default",
},
Source: v1alpha1.ApplicationSource{
RepoURL: "https://github.com/argoproj/argocd-example-apps",
Path: "guestbook",
TargetRevision: "123",
},
Project: "prj",
},
Status: v1alpha1.ApplicationStatus{
Sync: v1alpha1.SyncStatus{
Status: "OutOfSync",
},
Health: v1alpha1.HealthStatus{
Status: "Healthy",
},
},
}
output := "wide"
printApplicationTable([]v1alpha1.Application{*app, *app}, &output)
return nil
})
assert.NoError(t, err)
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"
assert.Equal(t, output, expectation)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment