Skip to content

Commit

Permalink
refactor: add pkg and slice name expression string
Browse files Browse the repository at this point in the history
Add pkg and slice name expression string variables to remove duplication
and increase test coverage.
  • Loading branch information
rebornplusplus committed Feb 14, 2024
1 parent 604a00b commit 0f724ae
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,17 @@ func order(pkgs map[string]*Package, keys []SliceKey) ([]SliceKey, error) {
return order, nil
}

var pkgNameExpStr = `([a-z0-9](?:-?[.a-z0-9+]){1,})`
var sliceNameExpStr = `([a-z](?:-?[a-z0-9]){2,})`

// fnameExp matches the slice definition file basename.
var fnameExp = regexp.MustCompile(`^([a-z0-9](?:-?[.a-z0-9+]){1,})\.yaml$`)
var fnameExp = regexp.MustCompile(`^` + pkgNameExpStr + `\.yaml$`)

// snameExp matches only the slice name, without the leading package name.
var snameExp = regexp.MustCompile(`^([a-z](?:-?[a-z0-9]){2,})$`)
var snameExp = regexp.MustCompile(`^` + sliceNameExpStr + `$`)

// knameExp matches the slice full name in pkg_slice format.
var knameExp = regexp.MustCompile(`^([a-z0-9](?:-?[.a-z0-9+]){1,})_([a-z](?:-?[a-z0-9]){2,})$`)
var knameExp = regexp.MustCompile(`^` + pkgNameExpStr + `_` + sliceNameExpStr + `$`)

func ParseSliceKey(sliceKey string) (SliceKey, error) {
match := knameExp.FindStringSubmatch(sliceKey)
Expand Down

0 comments on commit 0f724ae

Please sign in to comment.