From 7819110808830548d89973815d90015ef670966a Mon Sep 17 00:00:00 2001 From: schakrad <58915923+schakrad@users.noreply.github.com> Date: Sun, 10 Sep 2023 03:28:26 -0700 Subject: [PATCH] fix for the testcase printTreeViewDetailed Signed-off-by: schakrad <58915923+schakrad@users.noreply.github.com> --- cmd/argocd/commands/app.go | 5 +++-- cmd/argocd/commands/app_test.go | 3 +-- cmd/argocd/commands/tree.go | 4 ++-- cmd/argocd/commands/tree_test.go | 6 ++++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/argocd/commands/app.go b/cmd/argocd/commands/app.go index 99a8c9ebeb11e..457ff463be393 100644 --- a/cmd/argocd/commands/app.go +++ b/cmd/argocd/commands/app.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/mattn/go-isatty" "io" "os" "reflect" @@ -15,6 +14,8 @@ import ( "time" "unicode/utf8" + "github.com/mattn/go-isatty" + "github.com/argoproj/gitops-engine/pkg/health" "github.com/argoproj/gitops-engine/pkg/sync/common" "github.com/argoproj/gitops-engine/pkg/sync/hook" @@ -1591,7 +1592,7 @@ func printTreeViewDetailed(nodeMapping map[string]argoappv1.ResourceNode, parent tbl := tableConfig() tbl.AddRow("GROUP", "NAMESPACE", "KIND", "NAME", "STATUS", "HEALTH", "HOOK", "MESSAGE", "RESOURCE STATUS", "REASON", "AGE") for uid := range parentNodes { - treeViewAppGetDetailed("", tbl, nodeMapping, parentChildMapping, nodeMapping[uid], mapNodeNameToResourceState) + detailedTreeViewAppGet("", tbl, nodeMapping, parentChildMapping, nodeMapping[uid], mapNodeNameToResourceState) } fmt.Fprintln(w, tbl) } diff --git a/cmd/argocd/commands/app_test.go b/cmd/argocd/commands/app_test.go index 120b5beaacb84..549a15dfb45f6 100644 --- a/cmd/argocd/commands/app_test.go +++ b/cmd/argocd/commands/app_test.go @@ -118,8 +118,7 @@ func TestFindRevisionHistoryWithoutPassedId(t *testing.T) { func TestPrintTreeViewDetailed(t *testing.T) { var nodes [3]v1alpha1.ResourceNode nodes[0].ResourceRef = v1alpha1.ResourceRef{Group: "", Version: "v1", Kind: "Pod", Namespace: "sandbox-rollout-numalogic-demo", Name: "numalogic-rollout-demo-5dcd5457d5-6trpt", UID: "92c3a5fe-d13e-4ae2-b8ec-c10dd3543b28"} - nodes[0].Health.Status = "Degraded" - nodes[0].Health.Message = "Readiness Gate failed" + nodes[0].Health = &v1alpha1.HealthStatus{Status: "Degraded", Message: "Readiness Gate failed"} nodes[0].ParentRefs = []v1alpha1.ResourceRef{{Group: "apps", Version: "v1", Kind: "ReplicaSet", Namespace: "sandbox-rollout-numalogic-demo", Name: "numalogic-rollout-demo-5dcd5457d5", UID: "75c30dce-1b66-414f-a86c-573a74be0f40"}} nodes[1].ResourceRef = v1alpha1.ResourceRef{Group: "apps", Version: "v1", Kind: "ReplicaSet", Namespace: "sandbox-rollout-numalogic-demo", Name: "numalogic-rollout-demo-5dcd5457d5", UID: "75c30dce-1b66-414f-a86c-573a74be0f40"} nodes[1].ParentRefs = []v1alpha1.ResourceRef{{Group: "argoproj.io", Version: "", Kind: "Rollout", Namespace: "sandbox-rollout-numalogic-demo", Name: "numalogic-rollout-demo", UID: "87f3aab0-f634-4b2c-959a-7ddd30675ed0"}} diff --git a/cmd/argocd/commands/tree.go b/cmd/argocd/commands/tree.go index 806bb4789aff7..8ea137644b1fe 100644 --- a/cmd/argocd/commands/tree.go +++ b/cmd/argocd/commands/tree.go @@ -34,7 +34,7 @@ func extractHealthStatusAndReason(node v1alpha1.ResourceNode) (healthStatus heal return } -func treeViewAppGetDetailed(prefix string, tbl *uitable.Table, objs map[string]v1alpha1.ResourceNode, obj map[string][]string, parent v1alpha1.ResourceNode, mapNodeNameToResourceState map[string]*resourceState) { +func detailedTreeViewAppGet(prefix string, tbl *uitable.Table, objs map[string]v1alpha1.ResourceNode, obj map[string][]string, parent v1alpha1.ResourceNode, mapNodeNameToResourceState map[string]*resourceState) { healthStatus, reason := extractHealthStatusAndReason(parent) var readyColor *color.Color @@ -89,7 +89,7 @@ func treeViewAppGetDetailed(prefix string, tbl *uitable.Table, objs map[string]v default: p = prefix + firstElemPrefix } - treeViewAppGetDetailed(p, tbl, objs, obj, objs[child], mapNodeNameToResourceState) + detailedTreeViewAppGet(p, tbl, objs, obj, objs[child], mapNodeNameToResourceState) } } diff --git a/cmd/argocd/commands/tree_test.go b/cmd/argocd/commands/tree_test.go index aba05fe23d2ed..471fb25c195a5 100644 --- a/cmd/argocd/commands/tree_test.go +++ b/cmd/argocd/commands/tree_test.go @@ -16,7 +16,7 @@ func TestTreeViewAppGetDetailed(t *testing.T) { var child v1alpha1.ResourceNode child.ResourceRef = v1alpha1.ResourceRef{Group: "apps", Version: "v1", Kind: "ReplicaSet", Namespace: "sandbox-rollout-numalogic-demo", Name: "numalogic-rollout-demo-5dcd5457d5", UID: "75c30dce-1b66-414f-a86c-573a74be0f40"} child.ParentRefs = []v1alpha1.ResourceRef{{Group: "argoproj.io", Version: "", Kind: "Rollout", Namespace: "sandbox-rollout-numalogic-demo", Name: "numalogic-rollout-demo", UID: "87f3aab0-f634-4b2c-959a-7ddd30675ed0"}} - + child.Health = &v1alpha1.HealthStatus{Status: "Degraded", Message: "Readiness Gate failed"} objs["75c30dce-1b66-414f-a86c-573a74be0f40"] = child childMapping := make(map[string][]string) @@ -35,7 +35,7 @@ func TestTreeViewAppGetDetailed(t *testing.T) { tbl := uitable.New() - treeViewAppGetDetailed("", tbl, objs, childMapping, parent, stateMap) + detailedTreeViewAppGet("", tbl, objs, childMapping, parent, stateMap) output := tbl.String() @@ -45,6 +45,8 @@ func TestTreeViewAppGetDetailed(t *testing.T) { assert.Contains(t, output, "Healthy") assert.Contains(t, output, "No Issues") assert.Contains(t, output, "argoproj.io") + assert.Contains(t, output, "Degraded") + assert.Contains(t, output, "Readiness Gate failed") } func TestPrintPrefix(t *testing.T) {