github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/integration/v7/isolated/buildpacks_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"regexp"
     5  
     6  	. "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("buildpacks command", func() {
    15  	When("--help is passed", func() {
    16  		It("appears in cf help -a", func() {
    17  			session := helpers.CF("help", "-a")
    18  			Eventually(session).Should(Exit(0))
    19  			Expect(session).To(HaveCommandInCategoryWithDescription("buildpacks", "BUILDPACKS", "List all buildpacks"))
    20  		})
    21  
    22  		It("displays the help message", func() {
    23  			session := helpers.CF("buildpacks", "--help")
    24  			Eventually(session).Should(Say("NAME:"))
    25  			Eventually(session).Should(Say("buildpacks - List all buildpacks"))
    26  			Eventually(session).Should(Say("USAGE:"))
    27  			Eventually(session).Should(Say(regexp.QuoteMeta("cf buildpacks [--labels SELECTOR]")))
    28  			Eventually(session).Should(Say("EXAMPLES:"))
    29  			Eventually(session).Should(Say("cf buildpacks"))
    30  			Eventually(session).Should(Say(regexp.QuoteMeta("cf buildpacks --labels 'environment in (production,staging),tier in (backend)'")))
    31  			Eventually(session).Should(Say(regexp.QuoteMeta("cf buildpacks --labels 'env=dev,!chargeback-code,tier in (backend,worker)'")))
    32  			Eventually(session).Should(Say("OPTIONS:"))
    33  			Eventually(session).Should(Say(`--labels\s+Selector to filter buildpacks by labels`))
    34  			Eventually(session).Should(Say("SEE ALSO:"))
    35  			Eventually(session).Should(Say("create-buildpack, delete-buildpack, rename-buildpack, update-buildpack"))
    36  			Eventually(session).Should(Exit(0))
    37  		})
    38  	})
    39  
    40  	When("environment is not set up", func() {
    41  		It("displays an error and exits 1", func() {
    42  			helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "buildpacks")
    43  		})
    44  	})
    45  
    46  	When("the targeted API supports stack association", func() {
    47  		BeforeEach(func() {
    48  			helpers.LoginCF()
    49  		})
    50  
    51  		It("lists the buildpacks with the stack column", func() {
    52  			session := helpers.CF("buildpacks")
    53  
    54  			username, _ := helpers.GetCredentials()
    55  			Eventually(session).Should(Say("Getting buildpacks as %s...", username))
    56  			Eventually(session).Should(Say(`position\s+name\s+stack\s+enabled\s+locked\s+state\s+filename`))
    57  
    58  			positionRegex := `\d+`
    59  			enabledRegex := `true`
    60  			lockedRegex := `false`
    61  			stackRegex := `(cflinuxfs[23]|windows.+)`
    62  			stateRegex := `READY`
    63  
    64  			staticfileNameRegex := `staticfile_buildpack`
    65  			// staticfileFileRegex := `staticfile[-_]buildpack-\S+`
    66  			staticfileFileRegex := ""
    67  			Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
    68  				positionRegex,
    69  				staticfileNameRegex,
    70  				stackRegex,
    71  				enabledRegex,
    72  				lockedRegex,
    73  				stateRegex,
    74  				staticfileFileRegex))
    75  
    76  			binaryNameRegex := `binary_buildpack`
    77  			// binaryFileRegex := `binary[-_]buildpack-\S+`
    78  			binaryFileRegex := ""
    79  			Eventually(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
    80  				positionRegex,
    81  				binaryNameRegex,
    82  				stackRegex,
    83  				enabledRegex,
    84  				lockedRegex,
    85  				stateRegex,
    86  				binaryFileRegex))
    87  			Eventually(session).Should(Exit(0))
    88  		})
    89  
    90  		When("the --labels flag is given", func() {
    91  			When("the --labels selector is malformed", func() {
    92  				It("errors", func() {
    93  					session := helpers.CF("buildpacks", "--labels", "malformed in (")
    94  					Eventually(session).Should(Exit(1))
    95  				})
    96  			})
    97  
    98  			When("there are buildpacks with labels", func() {
    99  				var (
   100  					buildpack1 string
   101  					buildpack2 string
   102  				)
   103  
   104  				BeforeEach(func() {
   105  					buildpack1 = helpers.NewBuildpackName()
   106  					buildpack2 = helpers.NewBuildpackName()
   107  					helpers.SetupBuildpackWithoutStack(buildpack1)
   108  					helpers.SetupBuildpackWithoutStack(buildpack2)
   109  					Eventually(helpers.CF("set-label", "buildpack", buildpack1, "environment=production", "tier=backend")).Should(Exit(0))
   110  					Eventually(helpers.CF("set-label", "buildpack", buildpack2, "environment=staging", "tier=frontend")).Should(Exit(0))
   111  				})
   112  
   113  				AfterEach(func() {
   114  					Eventually(helpers.CF("delete-buildpack", buildpack1, "-f")).Should(Exit(0))
   115  					Eventually(helpers.CF("delete-buildpack", buildpack2, "-f")).Should(Exit(0))
   116  				})
   117  
   118  				It("lists the filtered buildpacks", func() {
   119  					session := helpers.CF("buildpacks", "--labels", "tier=frontend")
   120  					Eventually(session).Should(Exit(0))
   121  
   122  					username, _ := helpers.GetCredentials()
   123  					Expect(session).Should(Say("Getting buildpacks as %s...", username))
   124  					Expect(session).Should(Say(`position\s+name\s+stack\s+enabled\s+locked\s+state\s+filename`))
   125  
   126  					re := regexp.MustCompile(`(?:\n|\r)\d+\s+\w{8}`)
   127  					buildpackMatches := re.FindAll(session.Out.Contents(), -1)
   128  					Expect(len(buildpackMatches)).To(Equal(1))
   129  
   130  					positionRegex := `\d+`
   131  					enabledRegex := `true`
   132  					lockedRegex := `false`
   133  					stackRegex := ``
   134  					stateRegex := `READY`
   135  
   136  					Expect(session).Should(Say(`%s\s+%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
   137  						positionRegex,
   138  						buildpack2,
   139  						stackRegex,
   140  						enabledRegex,
   141  						lockedRegex,
   142  						stateRegex,
   143  						""))
   144  				})
   145  			})
   146  		})
   147  	})
   148  })