From 97f9c485d71759368113c72fcbff577589c8541b Mon Sep 17 00:00:00 2001 From: Ahmad ATWI Date: Fri, 27 Sep 2024 11:39:13 +0200 Subject: [PATCH] [#674] Implement the Variant Checker - Implement the function variant.checkVariant - Rename checkWorkflowConfiguration to checkVariantConfiguration - Add tests to verify the function variant.checkVariant - Allowed variant names to be case-insensitive --- .../{check_workflow.go => check_variant.go} | 28 ++++-- src/checker/check_variant_test.go | 89 +++++++++++++++++++ src/checker/check_workflow_test.go | 36 -------- src/checker/runner.go | 2 +- src/variant/variant.go | 7 +- src/variant/variant_test.go | 2 + 6 files changed, 116 insertions(+), 48 deletions(-) rename src/checker/{check_workflow.go => check_variant.go} (57%) create mode 100644 src/checker/check_variant_test.go delete mode 100644 src/checker/check_workflow_test.go diff --git a/src/checker/check_workflow.go b/src/checker/check_variant.go similarity index 57% rename from src/checker/check_workflow.go rename to src/checker/check_variant.go index 325c6e89..3446ca06 100644 --- a/src/checker/check_workflow.go +++ b/src/checker/check_variant.go @@ -25,26 +25,36 @@ package checker import ( "github.com/murex/tcr/checker/model" "github.com/murex/tcr/params" + "github.com/murex/tcr/variant" + "strings" ) -var checkWorkflowRunners []checkPointRunner +var checkVariantRunners []checkPointRunner func init() { - checkWorkflowRunners = []checkPointRunner{ - checkVariant, + checkVariantRunners = []checkPointRunner{ + checkVariantSelection, } } -func checkWorkflowConfiguration(p params.Params) (cg *model.CheckGroup) { - cg = model.NewCheckGroup("TCR workflow configuration") - for _, runner := range checkWorkflowRunners { +func checkVariantConfiguration(p params.Params) (cg *model.CheckGroup) { + cg = model.NewCheckGroup("TCR variant configuration") + for _, runner := range checkVariantRunners { cg.Add(runner(p)...) } return cg } -func checkVariant(_ params.Params) (cp []model.CheckPoint) { - cp = append(cp, model.WarningCheckPoint( - "variant checker TODO")) +func checkVariantSelection(p params.Params) (cp []model.CheckPoint) { + switch variantName := strings.ToLower(p.Variant); variantName { + case variant.Relaxed.Name(), variant.BTCR.Name(), variant.Introspective.Name(): + cp = append(cp, model.OkCheckPoint("selected variant is ", variantName)) + case "original": + cp = append(cp, model.ErrorCheckPoint("original variant is not yet supported")) + case "": + cp = append(cp, model.ErrorCheckPoint("no variant is selected")) + default: + cp = append(cp, model.ErrorCheckPoint("selected variant is not supported: \"", variantName, "\"")) + } return cp } diff --git a/src/checker/check_variant_test.go b/src/checker/check_variant_test.go new file mode 100644 index 00000000..adb97c64 --- /dev/null +++ b/src/checker/check_variant_test.go @@ -0,0 +1,89 @@ +/* +Copyright (c) 2023 Murex + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +package checker + +import ( + "github.com/murex/tcr/checker/model" + "github.com/murex/tcr/params" + "github.com/stretchr/testify/assert" + "testing" +) + +func Test_check_variant_configuration(t *testing.T) { + assertCheckGroupRunner(t, + checkVariantConfiguration, + &checkVariantRunners, + *params.AParamSet(), + "TCR variant configuration") +} + +func Test_check_variant_selection(t *testing.T) { + tests := []struct { + desc string + variantName string + expected []model.CheckPoint + }{ + { + "empty", "", + []model.CheckPoint{ + model.ErrorCheckPoint("no variant is selected"), + }, + }, + { + "unknown", "unknown-variant", + []model.CheckPoint{ + model.ErrorCheckPoint("selected variant is not supported: \"unknown-variant\""), + }, + }, + { + "Original", "original", + []model.CheckPoint{ + model.ErrorCheckPoint("original variant is not yet supported"), + }, + }, + { + "Introspective", "introspective", + []model.CheckPoint{ + model.OkCheckPoint("selected variant is introspective"), + }, + }, + { + "BTCR", "btcr", + []model.CheckPoint{ + model.OkCheckPoint("selected variant is btcr"), + }, + }, + { + "Relaxed", "relaxed", + []model.CheckPoint{ + model.OkCheckPoint("selected variant is relaxed"), + }, + }, + } + for _, test := range tests { + t.Run(test.desc, func(t *testing.T) { + p := *params.AParamSet(params.WithVariant(test.variantName)) + assert.Equal(t, test.expected, checkVariantSelection(p)) + }) + } +} diff --git a/src/checker/check_workflow_test.go b/src/checker/check_workflow_test.go deleted file mode 100644 index 5d7d275f..00000000 --- a/src/checker/check_workflow_test.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright (c) 2023 Murex - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ - -package checker - -import ( - "github.com/murex/tcr/params" - "testing" -) - -func Test_check_workflow_configuration(t *testing.T) { - assertCheckGroupRunner(t, - checkWorkflowConfiguration, - &checkWorkflowRunners, - *params.AParamSet(), - "TCR workflow configuration") -} diff --git a/src/checker/runner.go b/src/checker/runner.go index 8a8002f2..05c87446 100644 --- a/src/checker/runner.go +++ b/src/checker/runner.go @@ -61,7 +61,7 @@ var checkGroupRunners = []checkGroupRunner{ checkVCSConfiguration, checkGitEnvironment, checkP4Environment, - checkWorkflowConfiguration, + checkVariantConfiguration, checkMobConfiguration, } diff --git a/src/variant/variant.go b/src/variant/variant.go index 8fd189df..c086989c 100644 --- a/src/variant/variant.go +++ b/src/variant/variant.go @@ -22,7 +22,10 @@ SOFTWARE. package variant -import "fmt" +import ( + "fmt" + "strings" +) // UnsupportedVariantError is returned when the provided Variant name is not supported. type UnsupportedVariantError struct { @@ -53,7 +56,7 @@ var recognized = []Variant{Relaxed, BTCR, Introspective} // valid variant name. func Select(name string) (*Variant, error) { for _, variant := range recognized { - if name == variant.Name() { + if strings.ToLower(name) == strings.ToLower(variant.Name()) { return &variant, nil } } diff --git a/src/variant/variant_test.go b/src/variant/variant_test.go index 1cbc29f8..40d6883f 100644 --- a/src/variant/variant_test.go +++ b/src/variant/variant_test.go @@ -53,7 +53,9 @@ func Test_select_variant(t *testing.T) { expectedError error }{ {"relaxed", &relaxed, nil}, + {"Relaxed", &relaxed, nil}, {"btcr", &btcr, nil}, + {"BTCR", &btcr, nil}, {"introspective", &introspective, nil}, {"unknown", nil, &UnsupportedVariantError{"unknown"}}, {"", nil, &UnsupportedVariantError{""}},