Skip to content

Commit

Permalink
Change validate method to IsPathKind function
Browse files Browse the repository at this point in the history
  • Loading branch information
dobsonj committed Apr 30, 2021
1 parent 8e3f193 commit c19211e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/sanity/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,16 @@ const (
PathIsOther PathKind = "other"
)

func (pk PathKind) validate() error {
// IsPathKind validates that the input string matches one of the defined
// PathKind values above. If successful, it returns the corresponding
// PathKind type. Otherwise, it returns an error.
func IsPathKind(in string) (PathKind, error) {
pk := PathKind(in)
switch pk {
case PathIsFile, PathIsDir, PathIsNotFound, PathIsOther:
return nil
return pk, nil
default:
return fmt.Errorf("invalid PathType: %s", pk)
return pk, fmt.Errorf("invalid PathType: %s", pk)
}
}

Expand Down Expand Up @@ -528,8 +532,8 @@ func CheckPath(path string, config *TestConfig) (PathKind, error) {
}
// The output of this command is expected to match the value for
// PathIsFile, PathIsDir, PathIsNotFound, or PathIsOther.
pk := PathKind(strings.TrimSpace(string(out)))
if err = pk.validate(); err != nil {
pk, err := IsPathKind(strings.TrimSpace(string(out)))
if err != nil {
return "", fmt.Errorf("check path command %s failed: %v", config.CheckPathCmd, err)
}
return pk, nil
Expand Down

0 comments on commit c19211e

Please sign in to comment.