Skip to content

Commit

Permalink
chore: display jenkins job type in runner column (#421)
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Buccarella <m.buccarella@gmail.com>
  • Loading branch information
buccarel authored Nov 8, 2023
1 parent 5db910d commit 253d3f6
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
22 changes: 13 additions & 9 deletions app/cli/internal/action/workflow_run_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,18 @@ 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:
return "Unspecified"
mapping := map[v1.CraftingSchema_Runner_RunnerType]string{
*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, ok := mapping[in]
if !ok {
return "Unknown"
}

return hrt
}
83 changes: 83 additions & 0 deletions app/cli/internal/action/workflow_run_list_test.go
Original file line number Diff line number Diff line change
@@ -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(
nTestCases-1,
nRunnerTypes,
"%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))
}

0 comments on commit 253d3f6

Please sign in to comment.