Skip to content

Commit

Permalink
refactor: add WithNameEx() func to wrap arbitrary regex rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Apr 18, 2024
1 parent 89a38e0 commit 19a4721
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/config/with.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package config

import (
"github.com/ivanilves/travelgrunt/pkg/config/rule"
)

// WithNameEx returns a copy of config with regex-based rule added
func (cfg Config) WithNameEx(nameEx string) Config {
cfg.Rules = append(cfg.Rules, rule.Rule{NameEx: nameEx})

return cfg
}
19 changes: 19 additions & 0 deletions pkg/config/with_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package config

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestWithNameEx(t *testing.T) {
assert := assert.New(t)

cfg := DefaultConfig()

n := len(cfg.Rules)

cfg = cfg.WithNameEx("*.tf")

assert.Len(cfg.Rules, n+1)
}

0 comments on commit 19a4721

Please sign in to comment.