|
| 1 | +// |
| 2 | +// Copyright 2023 The Chainloop Authors. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +package action |
| 17 | + |
| 18 | +import ( |
| 19 | + "testing" |
| 20 | + |
| 21 | + v1 "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1" |
| 22 | + "github.com/stretchr/testify/suite" |
| 23 | +) |
| 24 | + |
| 25 | +type workflowRunListSuite struct { |
| 26 | + suite.Suite |
| 27 | +} |
| 28 | + |
| 29 | +func (s *workflowRunListSuite) TestHumanizedRunnerType() { |
| 30 | + testCases := []struct { |
| 31 | + name string |
| 32 | + testInput v1.CraftingSchema_Runner_RunnerType |
| 33 | + expectedOutput string |
| 34 | + }{ |
| 35 | + { |
| 36 | + name: "unspecified runner", |
| 37 | + testInput: v1.CraftingSchema_Runner_RUNNER_TYPE_UNSPECIFIED, |
| 38 | + expectedOutput: "Unspecified", |
| 39 | + }, { |
| 40 | + name: "github runner", |
| 41 | + testInput: v1.CraftingSchema_Runner_GITHUB_ACTION, |
| 42 | + expectedOutput: "GitHub", |
| 43 | + }, { |
| 44 | + name: "gitlab runner", |
| 45 | + testInput: v1.CraftingSchema_Runner_GITLAB_PIPELINE, |
| 46 | + expectedOutput: "GitLab", |
| 47 | + }, { |
| 48 | + name: "azure runner", |
| 49 | + testInput: v1.CraftingSchema_Runner_AZURE_PIPELINE, |
| 50 | + expectedOutput: "Azure Pipeline", |
| 51 | + }, { |
| 52 | + name: "jenkins runner", |
| 53 | + testInput: v1.CraftingSchema_Runner_JENKINS_JOB, |
| 54 | + expectedOutput: "Jenkins Job", |
| 55 | + }, { |
| 56 | + name: "unknown runner", |
| 57 | + testInput: -34, |
| 58 | + expectedOutput: "Unknown", |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + // enforce 1 test case per runner (+ the unknown) |
| 63 | + nRunnerTypes := len(v1.CraftingSchema_Runner_RunnerType_name) |
| 64 | + nTestCases := len(testCases) |
| 65 | + s.Equal( |
| 66 | + nTestCases-1, |
| 67 | + nRunnerTypes, |
| 68 | + "%d runners detected vs. %d test entries", |
| 69 | + nRunnerTypes, |
| 70 | + nTestCases-1, |
| 71 | + ) |
| 72 | + |
| 73 | + for _, testCase := range testCases { |
| 74 | + s.T().Run(testCase.name, func(t *testing.T) { |
| 75 | + result := humanizedRunnerType(testCase.testInput) |
| 76 | + s.Equal(testCase.expectedOutput, result) |
| 77 | + }) |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +func TestWorkflowRunlist(t *testing.T) { |
| 82 | + suite.Run(t, new(workflowRunListSuite)) |
| 83 | +} |
0 commit comments