From c489c3076241ddadcbd834e30947359ad5aa0101 Mon Sep 17 00:00:00 2001 From: Mattia Buccarella Date: Wed, 8 Nov 2023 11:59:36 +0100 Subject: [PATCH 1/4] chore: display jenkins job type in runner column Signed-off-by: Mattia Buccarella --- app/cli/internal/action/workflow_run_list.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/cli/internal/action/workflow_run_list.go b/app/cli/internal/action/workflow_run_list.go index 3bd5d1048..18d32b412 100644 --- a/app/cli/internal/action/workflow_run_list.go +++ b/app/cli/internal/action/workflow_run_list.go @@ -110,14 +110,17 @@ func pbWorkflowRunItemToAction(in *pb.WorkflowRunItem) *WorkflowRunItem { } func humanizedRunnerType(in v1.CraftingSchema_Runner_RunnerType) string { - switch in { - case *v1.CraftingSchema_Runner_GITHUB_ACTION.Enum(): - return "GitHub" - case *v1.CraftingSchema_Runner_GITLAB_PIPELINE.Enum(): - return "GitLab" - case *v1.CraftingSchema_Runner_AZURE_PIPELINE.Enum(): - return "Azure Pipeline" - default: + mapping := map[v1.CraftingSchema_Runner_RunnerType]string{ + *v1.CraftingSchema_Runner_GITHUB_ACTION.Enum(): "GitHub", + *v1.CraftingSchema_Runner_GITLAB_PIPELINE.Enum(): "GitLab", + *v1.CraftingSchema_Runner_AZURE_PIPELINE.Enum(): "Azure Pipeline", + *v1.CraftingSchema_Runner_JENKINS_JOB.Enum(): "Jenkins Job", + } + + hrt := mapping[in] + if hrt == "" { return "Unspecified" } + + return hrt } From ad8eb337ec2a7d69553a640b642297d73411f5b7 Mon Sep 17 00:00:00 2001 From: Mattia Buccarella Date: Wed, 8 Nov 2023 12:22:53 +0100 Subject: [PATCH 2/4] diff between unspecified and unknown Signed-off-by: Mattia Buccarella --- app/cli/internal/action/workflow_run_list.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/cli/internal/action/workflow_run_list.go b/app/cli/internal/action/workflow_run_list.go index 18d32b412..664186f2a 100644 --- a/app/cli/internal/action/workflow_run_list.go +++ b/app/cli/internal/action/workflow_run_list.go @@ -111,15 +111,16 @@ func pbWorkflowRunItemToAction(in *pb.WorkflowRunItem) *WorkflowRunItem { func humanizedRunnerType(in v1.CraftingSchema_Runner_RunnerType) string { mapping := map[v1.CraftingSchema_Runner_RunnerType]string{ - *v1.CraftingSchema_Runner_GITHUB_ACTION.Enum(): "GitHub", - *v1.CraftingSchema_Runner_GITLAB_PIPELINE.Enum(): "GitLab", - *v1.CraftingSchema_Runner_AZURE_PIPELINE.Enum(): "Azure Pipeline", - *v1.CraftingSchema_Runner_JENKINS_JOB.Enum(): "Jenkins Job", + *v1.CraftingSchema_Runner_RUNNER_TYPE_UNSPECIFIED.Enum(): "Unspecified", + *v1.CraftingSchema_Runner_GITHUB_ACTION.Enum(): "GitHub", + *v1.CraftingSchema_Runner_GITLAB_PIPELINE.Enum(): "GitLab", + *v1.CraftingSchema_Runner_AZURE_PIPELINE.Enum(): "Azure Pipeline", + *v1.CraftingSchema_Runner_JENKINS_JOB.Enum(): "Jenkins Job", } hrt := mapping[in] if hrt == "" { - return "Unspecified" + return "Unknown" } return hrt From ba16dd7731ee53b50c5037ec85f17fe7cca3cf00 Mon Sep 17 00:00:00 2001 From: Mattia Buccarella Date: Wed, 8 Nov 2023 15:45:07 +0100 Subject: [PATCH 3/4] added test Signed-off-by: Mattia Buccarella --- app/cli/internal/action/workflow_run_list.go | 4 +- .../internal/action/workflow_run_list_test.go | 83 +++++++++++++++++++ 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 app/cli/internal/action/workflow_run_list_test.go diff --git a/app/cli/internal/action/workflow_run_list.go b/app/cli/internal/action/workflow_run_list.go index 664186f2a..64b18400a 100644 --- a/app/cli/internal/action/workflow_run_list.go +++ b/app/cli/internal/action/workflow_run_list.go @@ -118,8 +118,8 @@ func humanizedRunnerType(in v1.CraftingSchema_Runner_RunnerType) string { *v1.CraftingSchema_Runner_JENKINS_JOB.Enum(): "Jenkins Job", } - hrt := mapping[in] - if hrt == "" { + hrt, ok := mapping[in] + if !ok { return "Unknown" } diff --git a/app/cli/internal/action/workflow_run_list_test.go b/app/cli/internal/action/workflow_run_list_test.go new file mode 100644 index 000000000..5321ea534 --- /dev/null +++ b/app/cli/internal/action/workflow_run_list_test.go @@ -0,0 +1,83 @@ +// +// Copyright 2023 The Chainloop Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package action + +import ( + "testing" + + v1 "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1" + "github.com/stretchr/testify/suite" +) + +type workflowRunListSuite struct { + suite.Suite +} + +func (s *workflowRunListSuite) TestHumanizedRunnerType() { + testCases := []struct { + name string + testInput v1.CraftingSchema_Runner_RunnerType + expectedOutput string + }{ + { + name: "unspecified runner", + testInput: v1.CraftingSchema_Runner_RUNNER_TYPE_UNSPECIFIED, + expectedOutput: "Unspecified", + }, { + name: "github runner", + testInput: v1.CraftingSchema_Runner_GITHUB_ACTION, + expectedOutput: "GitHub", + }, { + name: "gitlab runner", + testInput: v1.CraftingSchema_Runner_GITLAB_PIPELINE, + expectedOutput: "GitLab", + }, { + name: "azure runner", + testInput: v1.CraftingSchema_Runner_AZURE_PIPELINE, + expectedOutput: "Azure Pipeline", + }, { + name: "jenkins runner", + testInput: v1.CraftingSchema_Runner_JENKINS_JOB, + expectedOutput: "Jenkins Job", + }, { + name: "unknown runner", + testInput: -34, + expectedOutput: "Unknown", + }, + } + + // enforce 1 test case per runner (+ the unknown) + nRunnerTypes := len(v1.CraftingSchema_Runner_RunnerType_name) + nTestCases := len(testCases) + s.Equal( + len(testCases)-1, + len(v1.CraftingSchema_Runner_RunnerType_name), + "%d runners detected vs. %d test entries", + nRunnerTypes, + nTestCases-1, + ) + + for _, testCase := range testCases { + s.T().Run(testCase.name, func(t *testing.T) { + result := humanizedRunnerType(testCase.testInput) + s.Equal(testCase.expectedOutput, result) + }) + } +} + +func TestWorkflowRunlist(t *testing.T) { + suite.Run(t, new(workflowRunListSuite)) +} From d1c7628015863e9c6521f95a8619b42589aac4c8 Mon Sep 17 00:00:00 2001 From: Mattia Buccarella Date: Wed, 8 Nov 2023 16:16:11 +0100 Subject: [PATCH 4/4] copy-paste fix Signed-off-by: Mattia Buccarella --- app/cli/internal/action/workflow_run_list_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/cli/internal/action/workflow_run_list_test.go b/app/cli/internal/action/workflow_run_list_test.go index 5321ea534..ab6ba318f 100644 --- a/app/cli/internal/action/workflow_run_list_test.go +++ b/app/cli/internal/action/workflow_run_list_test.go @@ -63,8 +63,8 @@ func (s *workflowRunListSuite) TestHumanizedRunnerType() { nRunnerTypes := len(v1.CraftingSchema_Runner_RunnerType_name) nTestCases := len(testCases) s.Equal( - len(testCases)-1, - len(v1.CraftingSchema_Runner_RunnerType_name), + nTestCases-1, + nRunnerTypes, "%d runners detected vs. %d test entries", nRunnerTypes, nTestCases-1,