Skip to content

Commit

Permalink
[#674] Implement the Variant Checker
Browse files Browse the repository at this point in the history
- Implement the function variant.checkVariant
- Rename checkWorkflowConfiguration to checkVariantConfiguration
- Add tests to verify the function variant.checkVariant
- Allowed variant names to be case-insensitive
  • Loading branch information
aatwi authored and mengdaming committed Oct 1, 2024
1 parent 25cfa77 commit 97f9c48
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 48 deletions.
28 changes: 19 additions & 9 deletions src/checker/check_workflow.go → src/checker/check_variant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
89 changes: 89 additions & 0 deletions src/checker/check_variant_test.go
Original file line number Diff line number Diff line change
@@ -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))
})
}
}
36 changes: 0 additions & 36 deletions src/checker/check_workflow_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion src/checker/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var checkGroupRunners = []checkGroupRunner{
checkVCSConfiguration,
checkGitEnvironment,
checkP4Environment,
checkWorkflowConfiguration,
checkVariantConfiguration,
checkMobConfiguration,
}

Expand Down
7 changes: 5 additions & 2 deletions src/variant/variant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/variant/variant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{""}},
Expand Down

0 comments on commit 97f9c48

Please sign in to comment.