2023-05-03 18:02:11 +02:00
|
|
|
//go:build unit
|
|
|
|
// +build unit
|
|
|
|
|
2021-07-26 07:47:43 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2021-11-18 08:24:00 +02:00
|
|
|
"fmt"
|
2021-07-26 07:47:43 +02:00
|
|
|
"io"
|
2022-03-17 13:09:16 +02:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2021-07-26 07:47:43 +02:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2021-11-18 08:24:00 +02:00
|
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
2021-07-26 07:47:43 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func evaluateConditionsGlobMock(pattern string) ([]string, error) {
|
|
|
|
matches := []string{}
|
|
|
|
switch pattern {
|
|
|
|
case "**/conf.js":
|
|
|
|
matches = append(matches, "conf.js")
|
|
|
|
case "**/package.json":
|
|
|
|
matches = append(matches, "package.json", "package/node_modules/lib/package.json", "node_modules/package.json", "test/package.json")
|
|
|
|
|
|
|
|
}
|
|
|
|
return matches, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func evaluateConditionsOpenFileMock(name string, _ map[string]string) (io.ReadCloser, error) {
|
|
|
|
var fileContent io.ReadCloser
|
|
|
|
switch name {
|
|
|
|
case "package.json":
|
2023-08-16 12:57:04 +02:00
|
|
|
fileContent = io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
{
|
|
|
|
"scripts": {
|
|
|
|
"npmScript": "echo test",
|
|
|
|
"npmScript2": "echo test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`))
|
|
|
|
case "_package.json":
|
2023-08-16 12:57:04 +02:00
|
|
|
fileContent = io.NopCloser(strings.NewReader("wrong json format"))
|
2021-07-26 07:47:43 +02:00
|
|
|
case "test/package.json":
|
2023-08-16 12:57:04 +02:00
|
|
|
fileContent = io.NopCloser(strings.NewReader("{}"))
|
2021-07-26 07:47:43 +02:00
|
|
|
}
|
|
|
|
return fileContent, nil
|
|
|
|
}
|
|
|
|
|
2023-08-10 13:11:33 +02:00
|
|
|
func TestRunConfigV1EvaluateConditionsV1(t *testing.T) {
|
2021-11-18 08:24:00 +02:00
|
|
|
config := Config{Stages: map[string]map[string]interface{}{
|
|
|
|
"Test Stage 1": {
|
2023-08-10 13:11:33 +02:00
|
|
|
"step1": true, // explicit activate
|
|
|
|
"step5": true, // explicit activate
|
|
|
|
"step2": false, // explicit deactivate
|
|
|
|
"testKey": "testVal", // some condition 1
|
|
|
|
"testKey2": "testVal2", // some condition 2
|
2021-11-18 08:24:00 +02:00
|
|
|
},
|
2022-03-10 14:35:28 +02:00
|
|
|
}}
|
2023-08-10 13:11:33 +02:00
|
|
|
filesMock := mock.FilesMock{}
|
|
|
|
envRootPath := ".pipeline"
|
2022-03-10 14:35:28 +02:00
|
|
|
|
2023-08-10 13:11:33 +02:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
pipelineConfig PipelineDefinitionV1
|
|
|
|
wantRunSteps map[string]map[string]bool
|
|
|
|
wantRunStages map[string]bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "all steps in stage are inactive",
|
|
|
|
pipelineConfig: PipelineDefinitionV1{Spec: Spec{Stages: []Stage{{DisplayName: "Test Stage 1",
|
|
|
|
Steps: []Step{{
|
|
|
|
Name: "step1",
|
|
|
|
NotActiveConditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
}, {
|
|
|
|
Name: "step2",
|
|
|
|
}, {
|
|
|
|
Name: "step3",
|
|
|
|
NotActiveConditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}}},
|
|
|
|
wantRunSteps: map[string]map[string]bool{
|
|
|
|
"Test Stage 1": {
|
|
|
|
"step1": false,
|
|
|
|
"step2": false,
|
|
|
|
"step3": false,
|
|
|
|
}},
|
|
|
|
wantRunStages: map[string]bool{"Test Stage 1": false},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "simple stepActive conditions",
|
|
|
|
pipelineConfig: PipelineDefinitionV1{Spec: Spec{Stages: []Stage{{DisplayName: "Test Stage 1",
|
|
|
|
Steps: []Step{{
|
|
|
|
Name: "step3",
|
|
|
|
Conditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
}, {
|
|
|
|
Name: "step4",
|
|
|
|
Conditions: []StepCondition{{ConfigKey: "notExistentKey"}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}}},
|
|
|
|
wantRunSteps: map[string]map[string]bool{
|
|
|
|
"Test Stage 1": {
|
|
|
|
"step3": true,
|
|
|
|
"step4": false,
|
|
|
|
}},
|
|
|
|
wantRunStages: map[string]bool{"Test Stage 1": true},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "explicit active/deactivate over stepActiveCondition",
|
|
|
|
pipelineConfig: PipelineDefinitionV1{Spec: Spec{Stages: []Stage{{DisplayName: "Test Stage 1",
|
|
|
|
Steps: []Step{{
|
|
|
|
Name: "step1",
|
|
|
|
Conditions: []StepCondition{{ConfigKey: "notExistentKey"}},
|
|
|
|
}, {
|
|
|
|
Name: "step2",
|
|
|
|
Conditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}}},
|
|
|
|
wantRunSteps: map[string]map[string]bool{
|
|
|
|
"Test Stage 1": {
|
|
|
|
"step1": true,
|
|
|
|
"step2": false,
|
|
|
|
}},
|
|
|
|
wantRunStages: map[string]bool{"Test Stage 1": true},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "stepNotActiveCondition over stepActiveCondition",
|
|
|
|
pipelineConfig: PipelineDefinitionV1{Spec: Spec{Stages: []Stage{{DisplayName: "Test Stage 1",
|
|
|
|
Steps: []Step{{
|
|
|
|
Name: "step3",
|
|
|
|
Conditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
NotActiveConditions: []StepCondition{{ConfigKey: "testKey2"}},
|
|
|
|
}, {
|
|
|
|
// false notActive condition
|
|
|
|
Name: "step4",
|
|
|
|
Conditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
NotActiveConditions: []StepCondition{{ConfigKey: "notExistentKey"}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}}},
|
|
|
|
wantRunSteps: map[string]map[string]bool{
|
|
|
|
"Test Stage 1": {
|
|
|
|
"step3": false,
|
|
|
|
"step4": true,
|
|
|
|
}},
|
|
|
|
wantRunStages: map[string]bool{"Test Stage 1": true},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "stepNotActiveCondition over explicitly activated step",
|
|
|
|
pipelineConfig: PipelineDefinitionV1{Spec: Spec{Stages: []Stage{{DisplayName: "Test Stage 1",
|
|
|
|
Steps: []Step{{
|
|
|
|
Name: "step1",
|
|
|
|
NotActiveConditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
}, {
|
|
|
|
Name: "step5",
|
|
|
|
NotActiveConditions: []StepCondition{{ConfigKey: "notExistentKey"}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}}},
|
|
|
|
wantRunSteps: map[string]map[string]bool{
|
|
|
|
"Test Stage 1": {
|
|
|
|
"step1": false,
|
|
|
|
"step5": true,
|
|
|
|
}},
|
|
|
|
wantRunStages: map[string]bool{"Test Stage 1": true},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "deactivate if only active step in stage",
|
|
|
|
pipelineConfig: PipelineDefinitionV1{Spec: Spec{Stages: []Stage{{DisplayName: "Test Stage 1",
|
|
|
|
Steps: []Step{{
|
|
|
|
Name: "step1",
|
|
|
|
NotActiveConditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
}, {
|
|
|
|
Name: "step2",
|
|
|
|
}, {
|
|
|
|
Name: "step3",
|
|
|
|
NotActiveConditions: []StepCondition{{OnlyActiveStepInStage: true}},
|
|
|
|
}, {
|
|
|
|
Name: "step4",
|
|
|
|
Conditions: []StepCondition{{ConfigKey: "keyNotExist"}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}}},
|
|
|
|
wantRunSteps: map[string]map[string]bool{
|
|
|
|
"Test Stage 1": {
|
|
|
|
"step1": false,
|
|
|
|
"step2": false,
|
|
|
|
"step3": false,
|
|
|
|
"step4": false,
|
|
|
|
}},
|
|
|
|
wantRunStages: map[string]bool{"Test Stage 1": false},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "OnlyActiveStepInStage: one of the next steps is active",
|
|
|
|
pipelineConfig: PipelineDefinitionV1{Spec: Spec{Stages: []Stage{{DisplayName: "Test Stage 1",
|
|
|
|
Steps: []Step{{
|
|
|
|
Name: "step1",
|
|
|
|
NotActiveConditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
}, {
|
|
|
|
Name: "step2",
|
|
|
|
}, {
|
|
|
|
Name: "step3",
|
|
|
|
Conditions: []StepCondition{{ConfigKey: "testKey"}},
|
|
|
|
NotActiveConditions: []StepCondition{{OnlyActiveStepInStage: true}},
|
|
|
|
}, {
|
|
|
|
Name: "step4",
|
|
|
|
Conditions: []StepCondition{{ConfigKey: "testKey2"}},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}}},
|
|
|
|
wantRunSteps: map[string]map[string]bool{
|
|
|
|
"Test Stage 1": {
|
|
|
|
"step1": false,
|
|
|
|
"step2": false,
|
|
|
|
"step3": true,
|
|
|
|
"step4": true,
|
|
|
|
}},
|
|
|
|
wantRunStages: map[string]bool{"Test Stage 1": true},
|
2022-03-10 14:35:28 +02:00
|
|
|
},
|
|
|
|
}
|
2023-08-10 13:11:33 +02:00
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
r := &RunConfigV1{PipelineConfig: tt.pipelineConfig}
|
|
|
|
assert.NoError(t, r.evaluateConditionsV1(&config, &filesMock, envRootPath),
|
|
|
|
fmt.Sprintf("evaluateConditionsV1() err, pipelineConfig = %v", tt.pipelineConfig),
|
|
|
|
)
|
2022-03-10 14:35:28 +02:00
|
|
|
|
2023-08-10 13:11:33 +02:00
|
|
|
assert.Equal(t, tt.wantRunSteps, r.RunSteps, "RunSteps mismatch")
|
|
|
|
assert.Equal(t, tt.wantRunStages, r.RunStages, "RunStages mismatch")
|
|
|
|
})
|
2022-03-10 14:35:28 +02:00
|
|
|
}
|
2021-11-18 08:24:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvaluateV1(t *testing.T) {
|
|
|
|
tt := []struct {
|
|
|
|
name string
|
|
|
|
config StepConfig
|
|
|
|
stepCondition StepCondition
|
2023-08-10 13:11:33 +02:00
|
|
|
runSteps map[string]bool
|
2021-11-18 08:24:00 +02:00
|
|
|
expected bool
|
|
|
|
expectedError error
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "Config condition - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"deployTool": "helm3",
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{Config: map[string][]interface{}{"deployTool": {"helm", "helm3", "kubectl"}}},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Config condition - false",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"deployTool": "notsupported",
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{Config: map[string][]interface{}{"deployTool": {"helm", "helm3", "kubectl"}}},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Config condition - integer - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"executors": 1,
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{Config: map[string][]interface{}{"executors": {1}}},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Config condition - wrong condition definition",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"deployTool": "helm3",
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{Config: map[string][]interface{}{"deployTool": {"helm", "helm3", "kubectl"}, "deployTool2": {"myTool"}}},
|
|
|
|
expectedError: fmt.Errorf("only one config key allowed per condition but 2 provided"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ConfigKey condition - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"dockerRegistryUrl": "https://my.docker.registry.url",
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{ConfigKey: "dockerRegistryUrl"},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "ConfigKey condition - false",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{ConfigKey: "dockerRegistryUrl"},
|
|
|
|
expected: false,
|
|
|
|
},
|
2022-08-12 09:02:15 +02:00
|
|
|
{
|
|
|
|
name: "nested ConfigKey condition - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"cloudFoundry": map[string]interface{}{"space": "dev"},
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{ConfigKey: "cloudFoundry/space"},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "nested ConfigKey condition - false",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"cloudFoundry": map[string]interface{}{"noSpace": "dev"},
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{ConfigKey: "cloudFoundry/space"},
|
|
|
|
expected: false,
|
|
|
|
},
|
2021-11-18 08:24:00 +02:00
|
|
|
{
|
|
|
|
name: "FilePattern condition - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{FilePattern: "**/conf.js"},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "FilePattern condition - false",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{FilePattern: "**/confx.js"},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "FilePatternFromConfig condition - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"newmanCollection": "**/*.postman_collection.json",
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{FilePatternFromConfig: "newmanCollection"},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "FilePatternFromConfig condition - false",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"newmanCollection": "**/*.postmanx_collection.json",
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{FilePatternFromConfig: "newmanCollection"},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "FilePatternFromConfig condition - false, empty value",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{
|
|
|
|
"newmanCollection": "",
|
|
|
|
}},
|
|
|
|
stepCondition: StepCondition{FilePatternFromConfig: "newmanCollection"},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "NpmScript condition - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{NpmScript: "testScript"},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "NpmScript condition - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{NpmScript: "missingScript"},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Inactive condition - false",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{Inactive: true},
|
|
|
|
expected: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Inactive condition - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{Inactive: false},
|
|
|
|
expected: true,
|
|
|
|
},
|
2022-03-17 13:09:16 +02:00
|
|
|
{
|
|
|
|
name: "CommonPipelineEnvironment - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{CommonPipelineEnvironment: map[string]interface{}{"myCpeTrueFile": "myTrueValue"}},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "CommonPipelineEnvironment - false",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{CommonPipelineEnvironment: map[string]interface{}{"myCpeTrueFile": "notMyTrueValue"}},
|
|
|
|
expected: false,
|
|
|
|
},
|
2022-08-29 13:44:32 +02:00
|
|
|
{
|
|
|
|
name: "CommonPipelineEnvironmentVariableExists - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{PipelineEnvironmentFilled: "custom/myCpeTrueFile"},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "CommonPipelineEnvironmentVariableExists - false",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{PipelineEnvironmentFilled: "custom/notMyCpeTrueFile"},
|
|
|
|
expected: false,
|
|
|
|
},
|
2023-08-10 13:11:33 +02:00
|
|
|
{
|
|
|
|
name: "NotActiveCondition: all previous steps are inactive",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{OnlyActiveStepInStage: true},
|
|
|
|
runSteps: map[string]bool{"step1": false, "step2": false},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "NotActiveCondition: one of the previous steps is active",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
stepCondition: StepCondition{OnlyActiveStepInStage: true},
|
|
|
|
runSteps: map[string]bool{"step1": false, "step2": false, "step3": true},
|
|
|
|
expected: false,
|
|
|
|
},
|
2021-11-18 08:24:00 +02:00
|
|
|
{
|
|
|
|
name: "No condition - true",
|
|
|
|
config: StepConfig{Config: map[string]interface{}{}},
|
|
|
|
expected: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
packageJson := `{
|
|
|
|
"scripts": {
|
|
|
|
"testScript": "whatever"
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
|
|
|
filesMock := mock.FilesMock{}
|
|
|
|
filesMock.AddFile("conf.js", []byte("//test"))
|
|
|
|
filesMock.AddFile("my.postman_collection.json", []byte("{}"))
|
|
|
|
filesMock.AddFile("package.json", []byte(packageJson))
|
|
|
|
|
2022-07-12 15:19:12 +02:00
|
|
|
dir := t.TempDir()
|
2022-03-17 13:09:16 +02:00
|
|
|
|
|
|
|
cpeDir := filepath.Join(dir, "commonPipelineEnvironment")
|
2022-08-29 13:44:32 +02:00
|
|
|
err := os.MkdirAll(filepath.Join(cpeDir, "custom"), 0700)
|
2022-03-17 13:09:16 +02:00
|
|
|
if err != nil {
|
2022-08-29 13:44:32 +02:00
|
|
|
t.Fatal("Failed to create sub directories")
|
2022-03-17 13:09:16 +02:00
|
|
|
}
|
2023-08-16 12:57:04 +02:00
|
|
|
os.WriteFile(filepath.Join(cpeDir, "myCpeTrueFile"), []byte("myTrueValue"), 0700)
|
|
|
|
os.WriteFile(filepath.Join(cpeDir, "custom", "myCpeTrueFile"), []byte("myTrueValue"), 0700)
|
2022-03-17 13:09:16 +02:00
|
|
|
|
2021-11-18 08:24:00 +02:00
|
|
|
for _, test := range tt {
|
|
|
|
t.Run(test.name, func(t *testing.T) {
|
2023-08-10 13:11:33 +02:00
|
|
|
active, err := test.stepCondition.evaluateV1(test.config, &filesMock, "dummy", dir, test.runSteps)
|
2021-11-18 08:24:00 +02:00
|
|
|
if test.expectedError == nil {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
} else {
|
|
|
|
assert.EqualError(t, err, fmt.Sprint(test.expectedError))
|
|
|
|
}
|
|
|
|
assert.Equal(t, test.expected, active)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEvaluateConditions(t *testing.T) {
|
2021-07-26 07:47:43 +02:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
customConfig *Config
|
|
|
|
stageConfig io.ReadCloser
|
|
|
|
runStepsExpected map[string]map[string]bool
|
|
|
|
globFunc func(pattern string) ([]string, error)
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "test config condition - success",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{
|
|
|
|
"testGeneral": "myVal1",
|
|
|
|
},
|
|
|
|
Stages: map[string]map[string]interface{}{
|
|
|
|
"testStage2": {
|
|
|
|
"testStage": "myVal2",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Steps: map[string]map[string]interface{}{
|
|
|
|
"thirdStep": {
|
|
|
|
"testStep1": "myVal3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
config: testGeneral
|
|
|
|
testStage2:
|
|
|
|
stepConditions:
|
|
|
|
secondStep:
|
|
|
|
config: testStage
|
|
|
|
testStage3:
|
|
|
|
stepConditions:
|
|
|
|
thirdStep:
|
|
|
|
config: testStep1
|
|
|
|
forthStep:
|
|
|
|
config: testStep2
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {"firstStep": true},
|
|
|
|
"testStage2": {"secondStep": true},
|
|
|
|
"testStage3": {
|
|
|
|
"thirdStep": true,
|
|
|
|
"forthStep": false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test config condition - wrong usage with list",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
2023-08-10 13:11:33 +02:00
|
|
|
config:
|
2021-07-26 07:47:43 +02:00
|
|
|
- testGeneral
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test config value condition - success",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{
|
|
|
|
"testGeneral": "myVal1",
|
|
|
|
},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{
|
|
|
|
"thirdStep": {
|
|
|
|
"testStep": "myVal3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
config:
|
|
|
|
testGeneral:
|
|
|
|
- myValx
|
|
|
|
- myVal1
|
|
|
|
testStage2:
|
|
|
|
stepConditions:
|
|
|
|
secondStep:
|
|
|
|
config:
|
|
|
|
testStage:
|
|
|
|
- maValXyz
|
|
|
|
testStage3:
|
|
|
|
stepConditions:
|
|
|
|
thirdStep:
|
|
|
|
config:
|
|
|
|
testStep:
|
|
|
|
- myVal3
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {"firstStep": true},
|
|
|
|
"testStage2": {"secondStep": false},
|
|
|
|
"testStage3": {"thirdStep": true},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test configKey condition - success",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{
|
|
|
|
"myKey1_1": "myVal1_1",
|
|
|
|
},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{
|
|
|
|
"thirdStep": {
|
|
|
|
"myKey3_1": "myVal3_1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
configKeys:
|
|
|
|
- myKey1_1
|
|
|
|
- myKey1_2
|
|
|
|
testStage2:
|
|
|
|
stepConditions:
|
|
|
|
secondStep:
|
|
|
|
configKeys:
|
|
|
|
- myKey2_1
|
|
|
|
testStage3:
|
|
|
|
stepConditions:
|
|
|
|
thirdStep:
|
|
|
|
configKeys:
|
|
|
|
- myKey3_1
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {"firstStep": true},
|
|
|
|
"testStage2": {"secondStep": false},
|
|
|
|
"testStage3": {"thirdStep": true},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test configKey condition - not list",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{
|
|
|
|
"myKey1_1": "myVal1_1",
|
|
|
|
},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
configKeys: myKey1_1
|
|
|
|
`)),
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test configKey condition - success",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{
|
|
|
|
"myKey1_1": "myVal1_1",
|
|
|
|
},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{
|
|
|
|
"thirdStep": {
|
|
|
|
"myKey3_1": "myVal3_1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
configKeys:
|
|
|
|
- myKey1_1
|
|
|
|
- myKey1_2
|
|
|
|
testStage2:
|
|
|
|
stepConditions:
|
|
|
|
secondStep:
|
|
|
|
configKeys:
|
|
|
|
- myKey2_1
|
|
|
|
testStage3:
|
|
|
|
stepConditions:
|
|
|
|
thirdStep:
|
|
|
|
configKeys:
|
|
|
|
- myKey3_1
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {"firstStep": true},
|
|
|
|
"testStage2": {"secondStep": false},
|
|
|
|
"testStage3": {"thirdStep": true},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test filePattern condition - success",
|
|
|
|
globFunc: evaluateConditionsGlobMock,
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
filePattern: '**/conf.js'
|
|
|
|
secondStep:
|
|
|
|
filePattern: '**/conf.jsx'
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {
|
|
|
|
"firstStep": true,
|
|
|
|
"secondStep": false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test filePattern condition - error while searching files by pattern",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
filePattern: '**/conf.js'
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{},
|
|
|
|
globFunc: func(pattern string) ([]string, error) {
|
|
|
|
return nil, errors.New("failed to check if file exists")
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test filePattern condition with list - success",
|
|
|
|
globFunc: evaluateConditionsGlobMock,
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
filePattern:
|
|
|
|
- '**/conf.js'
|
|
|
|
- 'myCollection.json'
|
|
|
|
secondStep:
|
2023-08-10 13:11:33 +02:00
|
|
|
filePattern:
|
2021-07-26 07:47:43 +02:00
|
|
|
- '**/conf.jsx'
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {
|
|
|
|
"firstStep": true,
|
|
|
|
"secondStep": false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test filePattern condition with list - error while searching files by pattern",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
filePattern:
|
|
|
|
- '**/conf.js'
|
|
|
|
- 'myCollection.json'
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{},
|
|
|
|
globFunc: func(pattern string) ([]string, error) {
|
|
|
|
return nil, errors.New("failed to check if file exists")
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test filePatternFromConfig condition - success",
|
|
|
|
globFunc: evaluateConditionsGlobMock,
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{
|
|
|
|
"firstStep": {
|
|
|
|
"myVal1": "**/conf.js",
|
|
|
|
},
|
|
|
|
"thirdStep": {
|
|
|
|
"myVal3": "**/conf.jsx",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
filePatternFromConfig: myVal1
|
|
|
|
secondStep:
|
|
|
|
filePatternFromConfig: myVal2
|
|
|
|
thirdStep:
|
|
|
|
filePatternFromConfig: myVal3
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {
|
|
|
|
"firstStep": true,
|
|
|
|
"secondStep": false,
|
|
|
|
"thirdStep": false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test filePatternFromConfig condition - error while searching files by pattern",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{
|
|
|
|
"firstStep": {
|
|
|
|
"myVal1": "**/conf.js",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
filePatternFromConfig: myVal1
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{},
|
|
|
|
globFunc: func(pattern string) ([]string, error) {
|
|
|
|
return nil, errors.New("failed to check if file exists")
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test npmScripts condition - success",
|
|
|
|
globFunc: evaluateConditionsGlobMock,
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
npmScripts: 'npmScript'
|
|
|
|
secondStep:
|
|
|
|
npmScripts: 'npmScript1'
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {
|
|
|
|
"firstStep": true,
|
|
|
|
"secondStep": false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test npmScripts condition with list - success",
|
|
|
|
globFunc: evaluateConditionsGlobMock,
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
npmScripts:
|
|
|
|
- 'npmScript'
|
|
|
|
- 'npmScript2'
|
|
|
|
secondStep:
|
|
|
|
npmScripts:
|
|
|
|
- 'npmScript3'
|
|
|
|
- 'npmScript4'
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {
|
|
|
|
"firstStep": true,
|
|
|
|
"secondStep": false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test npmScripts condition - json with wrong format",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
npmScripts:
|
|
|
|
- 'npmScript3'
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{},
|
|
|
|
globFunc: func(pattern string) ([]string, error) {
|
|
|
|
return []string{"_package.json"}, nil
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "test npmScripts condition - error while searching package.json",
|
|
|
|
customConfig: &Config{
|
|
|
|
General: map[string]interface{}{},
|
|
|
|
Stages: map[string]map[string]interface{}{},
|
|
|
|
Steps: map[string]map[string]interface{}{},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-07-26 07:47:43 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
npmScripts:
|
|
|
|
- 'npmScript3'
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{},
|
|
|
|
globFunc: func(pattern string) ([]string, error) {
|
|
|
|
return nil, errors.New("failed to check if file exists")
|
|
|
|
},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
2021-08-17 11:20:04 +02:00
|
|
|
{
|
|
|
|
name: "test explicit activation / de-activation of step",
|
|
|
|
customConfig: &Config{
|
|
|
|
Stages: map[string]map[string]interface{}{
|
|
|
|
"testStage1": {
|
|
|
|
"firstStep": true,
|
|
|
|
"fisecondStep": false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-08-16 12:57:04 +02:00
|
|
|
stageConfig: io.NopCloser(strings.NewReader(`
|
2021-08-17 11:20:04 +02:00
|
|
|
stages:
|
|
|
|
testStage1:
|
|
|
|
stepConditions:
|
|
|
|
firstStep:
|
|
|
|
config: testGeneral
|
|
|
|
secondStep:
|
|
|
|
config: testStage
|
|
|
|
`)),
|
|
|
|
runStepsExpected: map[string]map[string]bool{
|
|
|
|
"testStage1": {
|
|
|
|
"firstStep": true,
|
|
|
|
"secondStep": false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-07-26 07:47:43 +02:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
runConfig := RunConfig{
|
|
|
|
StageConfigFile: tt.stageConfig,
|
|
|
|
RunSteps: map[string]map[string]bool{},
|
|
|
|
OpenFile: evaluateConditionsOpenFileMock,
|
|
|
|
}
|
|
|
|
err := runConfig.loadConditions()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = runConfig.evaluateConditions(tt.customConfig, nil, nil, nil, nil, tt.globFunc)
|
|
|
|
if tt.wantErr {
|
|
|
|
assert.Error(t, err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, tt.runStepsExpected, runConfig.RunSteps)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-08-10 13:11:33 +02:00
|
|
|
|
|
|
|
func TestAnyOtherStepIsActive(t *testing.T) {
|
|
|
|
targetStep := "step3"
|
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
runSteps map[string]bool
|
|
|
|
want bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "all steps are inactive (target active)",
|
|
|
|
runSteps: map[string]bool{
|
|
|
|
"step1": false,
|
|
|
|
"step2": false,
|
|
|
|
"step3": true,
|
|
|
|
"step4": false,
|
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "all steps are inactive (target inactive)",
|
|
|
|
runSteps: map[string]bool{
|
|
|
|
"step1": false,
|
|
|
|
"step2": false,
|
|
|
|
"step3": false,
|
|
|
|
"step4": false,
|
|
|
|
},
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "some previous step is active",
|
|
|
|
runSteps: map[string]bool{
|
|
|
|
"step1": false,
|
|
|
|
"step2": true,
|
|
|
|
"step3": false,
|
|
|
|
"step4": false,
|
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "some next step is active",
|
|
|
|
runSteps: map[string]bool{
|
|
|
|
"step1": false,
|
|
|
|
"step2": false,
|
|
|
|
"step3": true,
|
|
|
|
"step4": true,
|
|
|
|
},
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, anyOtherStepIsActive(targetStep, tt.runSteps), "anyOtherStepIsActive(%v, %v)", targetStep, tt.runSteps)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|