Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Argo Cd
Commits
62e49739
Unverified
Commit
62e49739
authored
3 years ago
by
pasha-codefresh
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
chore: Print application table test (#9266)
parent
0f22d57a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cmd/argocd/commands/app_test.go
+91
-23
cmd/argocd/commands/app_test.go
with
91 additions
and
23 deletions
+91
-23
cmd/argocd/commands/app_test.go
+
91
-
23
View file @
62e49739
...
...
@@ -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,18 +23,18 @@ import (
)
func
Test_getInfos
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
name
string
infos
[]
string
testCases
:=
[]
struct
{
name
string
infos
[]
string
expectedInfos
[]
*
v1alpha1
.
Info
}{
{
name
:
"empty"
,
infos
:
[]
string
{},
name
:
"empty"
,
infos
:
[]
string
{},
expectedInfos
:
[]
*
v1alpha1
.
Info
{},
},
{
name
:
"simple key value"
,
name
:
"simple key value"
,
infos
:
[]
string
{
"key1=value1"
,
"key2=value2"
},
expectedInfos
:
[]
*
v1alpha1
.
Info
{
{
Name
:
"key1"
,
Value
:
"value1"
},
...
...
@@ -55,10 +56,10 @@ func Test_getInfos(t *testing.T) {
func
Test_getRefreshType
(
t
*
testing
.
T
)
{
refreshTypeNormal
:=
string
(
v1alpha1
.
RefreshTypeNormal
)
refreshTypeHard
:=
string
(
v1alpha1
.
RefreshTypeHard
)
testCases
:=
[]
struct
{
refresh
bool
testCases
:=
[]
struct
{
refresh
bool
hardRefresh
bool
expected
*
string
expected
*
string
}{
{
false
,
false
,
nil
},
{
false
,
true
,
&
refreshTypeHard
},
...
...
@@ -335,7 +336,7 @@ func Test_groupObjsByKey(t *testing.T) {
{
Object
:
map
[
string
]
interface
{}{
"apiVersion"
:
"apiextensions.k8s.io/v1"
,
"kind"
:
"CustomResourceDefinition"
,
"kind"
:
"CustomResourceDefinition"
,
"metadata"
:
map
[
string
]
interface
{}{
"name"
:
"certificates.cert-manager.io"
,
},
...
...
@@ -356,7 +357,7 @@ func Test_groupObjsByKey(t *testing.T) {
{
Object
:
map
[
string
]
interface
{}{
"apiVersion"
:
"apiextensions.k8s.io/v1"
,
"kind"
:
"CustomResourceDefinition"
,
"kind"
:
"CustomResourceDefinition"
,
"metadata"
:
map
[
string
]
interface
{}{
"name"
:
"certificates.cert-manager.io"
,
},
...
...
@@ -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"
)
...
...
@@ -581,7 +582,7 @@ func TestPrintAppSummaryTable(t *testing.T) {
windows
:=
&
v1alpha1
.
SyncWindows
{
{
Kind
:
"allow"
,
Kind
:
"allow"
,
Schedule
:
"0 0 * * *"
,
Duration
:
"24h"
,
Applications
:
[]
string
{
...
...
@@ -590,7 +591,7 @@ func TestPrintAppSummaryTable(t *testing.T) {
ManualSync
:
true
,
},
{
Kind
:
"deny"
,
Kind
:
"deny"
,
Schedule
:
"0 0 * * *"
,
Duration
:
"24h"
,
Namespaces
:
[]
string
{
...
...
@@ -598,7 +599,7 @@ func TestPrintAppSummaryTable(t *testing.T) {
},
},
{
Kind
:
"allow"
,
Kind
:
"allow"
,
Schedule
:
"0 0 * * *"
,
Duration
:
"24h"
,
Clusters
:
[]
string
{
...
...
@@ -839,11 +840,11 @@ func Test_unset(t *testing.T) {
Plugin
:
&
v1alpha1
.
ApplicationSourcePlugin
{
Env
:
v1alpha1
.
Env
{
{
Name
:
"env-1"
,
Name
:
"env-1"
,
Value
:
"env-value-1"
,
},
{
Name
:
"env-2"
,
Name
:
"env-2"
,
Value
:
"env-value-2"
,
},
},
...
...
@@ -942,8 +943,8 @@ func Test_unset(t *testing.T) {
}
func
Test_unset_nothingToUnset
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
name
string
testCases
:=
[]
struct
{
name
string
source
v1alpha1
.
ApplicationSource
}{
{
"kustomize"
,
v1alpha1
.
ApplicationSource
{
Kustomize
:
&
v1alpha1
.
ApplicationSourceKustomize
{}}},
...
...
@@ -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
\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
"
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
\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
"
assert
.
Equal
(
t
,
output
,
expectation
)
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help