-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add WithNameEx() func to wrap arbitrary regex rule
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |