github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/helpers/buildpack_v7.go (about)

     1  // +build V7
     2  
     3  package helpers
     4  
     5  import (
     6  	"fmt"
     7  	"regexp"
     8  )
     9  
    10  // BuildpacksOutputRegex takes a BuildpackFields struct and returns a regex
    11  // matching a line in the output of 'cf buildpacks' representing the given
    12  // buildpack.
    13  func BuildpacksOutputRegex(fields BuildpackFields) string {
    14  	anyStringRegex := `\S+`
    15  	optionalStringRegex := `\S*`
    16  	anyBoolRegex := `(true|false)`
    17  	anyIntRegex := `\d+`
    18  
    19  	nameRegex := anyStringRegex
    20  	if fields.Name != "" {
    21  		nameRegex = regexp.QuoteMeta(fields.Name)
    22  	}
    23  
    24  	positionRegex := anyIntRegex
    25  	if fields.Position != "" {
    26  		positionRegex = regexp.QuoteMeta(fields.Position)
    27  	}
    28  
    29  	enabledRegex := anyBoolRegex
    30  	if fields.Enabled != "" {
    31  		enabledRegex = regexp.QuoteMeta(fields.Enabled)
    32  	}
    33  
    34  	lockedRegex := anyBoolRegex
    35  	if fields.Locked != "" {
    36  		lockedRegex = regexp.QuoteMeta(fields.Locked)
    37  	}
    38  
    39  	filenameRegex := anyStringRegex
    40  	if fields.Filename != "" {
    41  		filenameRegex = regexp.QuoteMeta(fields.Filename)
    42  	}
    43  
    44  	stackRegex := optionalStringRegex
    45  	if fields.Stack != "" {
    46  		stackRegex = regexp.QuoteMeta(fields.Stack)
    47  	}
    48  
    49  	return fmt.Sprintf(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
    50  		positionRegex,
    51  		nameRegex,
    52  		stackRegex,
    53  		enabledRegex,
    54  		lockedRegex,
    55  		filenameRegex,
    56  	)
    57  }