Skip to content

Commit

Permalink
fix: add testcase
Browse files Browse the repository at this point in the history
Signed-off-by: kj455 <[email protected]>
  • Loading branch information
kj455 committed Feb 14, 2025
1 parent bc83f74 commit 14b52df
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/app/pipectl/cmd/planpreview/planpreview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ NOTE: An error occurred while building plan-preview for applications of the foll
}
}
func TestSortResults(t *testing.T) {
t.Parallel()
testcases := []struct {
name string
results []*model.PlanPreviewCommandResult
Expand Down Expand Up @@ -300,6 +301,8 @@ func TestSortResults(t *testing.T) {
{
PipedId: "piped-2",
Results: []*model.ApplicationPlanPreviewResult{
{ApplicationName: "app-3", Labels: map[string]string{"env": "staging"}},
{ApplicationName: "app-3", Labels: map[string]string{"env": "prod"}},
{ApplicationName: "app-2", Labels: map[string]string{"env": "staging"}},
{ApplicationName: "app-2", Labels: map[string]string{"env": "prod"}},
},
Expand All @@ -318,7 +321,35 @@ func TestSortResults(t *testing.T) {
PipedId: "piped-2",
Results: []*model.ApplicationPlanPreviewResult{
{ApplicationName: "app-2", Labels: map[string]string{"env": "prod"}},
{ApplicationName: "app-3", Labels: map[string]string{"env": "prod"}},
{ApplicationName: "app-2", Labels: map[string]string{"env": "staging"}},
{ApplicationName: "app-3", Labels: map[string]string{"env": "staging"}},
},
},
},
},
{
name: "sort by multiple label keys",
results: []*model.PlanPreviewCommandResult{
{
PipedId: "piped-1",
Results: []*model.ApplicationPlanPreviewResult{
{ApplicationName: "app-1", Labels: map[string]string{"env": "prod", "team": "team-2"}},
{ApplicationName: "app-1", Labels: map[string]string{"env": "staging", "team": "team-1"}},
{ApplicationName: "app-1", Labels: map[string]string{"env": "prod", "team": "team-1"}},
{ApplicationName: "app-2", Labels: map[string]string{"env": "prod", "team": "team-2"}},
},
},
},
sortLabelKeys: []string{"env", "team"},
expected: []*model.PlanPreviewCommandResult{
{
PipedId: "piped-1",
Results: []*model.ApplicationPlanPreviewResult{
{ApplicationName: "app-1", Labels: map[string]string{"env": "prod", "team": "team-1"}},
{ApplicationName: "app-1", Labels: map[string]string{"env": "prod", "team": "team-2"}},
{ApplicationName: "app-2", Labels: map[string]string{"env": "prod", "team": "team-2"}},
{ApplicationName: "app-1", Labels: map[string]string{"env": "staging", "team": "team-1"}},
},
},
},
Expand Down

0 comments on commit 14b52df

Please sign in to comment.