Skip to content

Commit

Permalink
fix: added support to any type
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessio Pragliola committed Jan 19, 2024
1 parent 8a5be35 commit 9a8e905
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
6 changes: 3 additions & 3 deletions internal/apis/kfd/v1alpha2/reducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type Reducer interface {

type BaseReducer struct {
Key string
From string
To string
From any
To any
Lifecycle string
}

func NewBaseReducer(key, from, to, lifecycle string) *BaseReducer {
func NewBaseReducer(key string, from, to any, lifecycle string) *BaseReducer {
return &BaseReducer{
Key: key,
From: from,
Expand Down
23 changes: 6 additions & 17 deletions internal/rules/extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"

"github.com/r3labs/diff/v3"
"github.com/sirupsen/logrus"
)

var numbersToWildcardRegex = regexp.MustCompile(`\.\d+\b`)
Expand All @@ -29,16 +28,16 @@ type Rule struct {
}

type Unsupported struct {
From *string `yaml:"from,omitempty"`
To *string `yaml:"to,omitempty"`
From *any `yaml:"from,omitempty"`
To *any `yaml:"to,omitempty"`
Reason *string `yaml:"reason,omitempty"`
}

type Reducer struct {
Key string `yaml:"key"`
Lifecycle string `yaml:"lifecycle"`
From string `yaml:"from"`
To string `yaml:"to"`
From any `yaml:"from"`
To any `yaml:"to"`
}

type Extractor interface {
Expand Down Expand Up @@ -131,19 +130,9 @@ func (*BaseExtractor) ReducerRulesByDiffs(rules []Rule, ds diff.Changelog) []Rul
continue
}

toStr, toOk := d.To.(string)

fromStr, fromOk := d.From.(string)

if !fromOk || !toOk {
logrus.Debugf("skipping reducer rule %s, from or to are not strings", rule.Path)

continue
}

for i := range *rule.Reducers {
(*rule.Reducers)[i].To = toStr
(*rule.Reducers)[i].From = fromStr
(*rule.Reducers)[i].To = d.To
(*rule.Reducers)[i].From = d.From
}

filteredRules = append(filteredRules, rule)
Expand Down
8 changes: 5 additions & 3 deletions internal/rules/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,11 @@ func TestBaseExtractor_ReducerRulesByDiffs(t *testing.T) {
func TestBaseExtractor_UnsupportedReducerRulesByDiffs(t *testing.T) {
t.Parallel()

foo := "foo"
bar := "bar"
baz := "baz"
var foo, bar, baz any

foo = "foo"
bar = "bar"
baz = "baz"

testCases := []struct {
name string
Expand Down

0 comments on commit 9a8e905

Please sign in to comment.