github.com/loafoe/cli@v7.1.0+incompatible/integration/v6/push/deprecated_route_flags_test.go (about)

     1  package push
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  
     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("deprecated route command-line flags", func() {
    15  
    16  	const deprecationTemplate = "Deprecation warning: Use of the '%[1]s' command-line flag option is deprecated in favor of the 'routes' property in the manifest. Please see https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html#routes for usage information. The '%[1]s' command-line flag option will be removed in the future."
    17  
    18  	const legacyManifestDeprecationTemplate = `Deprecation warning: Specifying app manifest attributes at the top level is deprecated. Found: host.
    19  Please see https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html#deprecated for alternatives and other app manifest deprecations. This feature will be removed in the future.`
    20  
    21  	var (
    22  		appName       string
    23  		host          string
    24  		privateDomain string
    25  		localArgs     []string
    26  		session       *Session
    27  	)
    28  
    29  	BeforeEach(func() {
    30  		appName = helpers.NewAppName()
    31  		host = helpers.NewAppName()
    32  
    33  		privateDomain = helpers.NewDomainName()
    34  		domain := helpers.NewDomain(organization, privateDomain)
    35  		domain.Create()
    36  	})
    37  	When("with no manifest", func() {
    38  		JustBeforeEach(func() {
    39  			helpers.WithHelloWorldApp(func(dir string) {
    40  				allArgs := []string{PushCommandName, appName, "--no-start"}
    41  				allArgs = append(allArgs, localArgs...)
    42  				session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, allArgs...)
    43  				Eventually(session).Should(Exit(0))
    44  			})
    45  		})
    46  
    47  		When("no deprecated flags are provided", func() {
    48  			BeforeEach(func() {
    49  				localArgs = []string{}
    50  			})
    51  			It("does not output a deprecation warning", func() {
    52  				Expect(string(session.Err.Contents())).ToNot(ContainSubstring("command-line flag option is deprecated in favor of the 'routes' property in the manifest"))
    53  			})
    54  		})
    55  
    56  		When("the -d (domains) flag is provided", func() {
    57  			BeforeEach(func() {
    58  				localArgs = []string{"-d", privateDomain}
    59  			})
    60  			It("outputs a deprecation warning", func() {
    61  				Expect(session.Err).Should(Say(deprecationTemplate, "-d"))
    62  			})
    63  		})
    64  
    65  		When("the --hostname flag is provided", func() {
    66  			BeforeEach(func() {
    67  				localArgs = []string{"--hostname", host}
    68  			})
    69  			It("outputs a deprecation warning", func() {
    70  				Expect(session.Err).Should(Say(deprecationTemplate, "--hostname"))
    71  			})
    72  		})
    73  
    74  		When("the --no-hostname flag is provided", func() {
    75  			BeforeEach(func() {
    76  				localArgs = []string{"--no-hostname", "-d", privateDomain}
    77  			})
    78  			It("outputs a deprecation warning", func() {
    79  				Expect(session.Err).Should(Say(deprecationTemplate, "--no-hostname"))
    80  			})
    81  		})
    82  
    83  		When("the --route-path flag is provided", func() {
    84  			BeforeEach(func() {
    85  				localArgs = []string{"--route-path", "some-path"}
    86  			})
    87  			It("outputs a deprecation warning", func() {
    88  				Expect(session.Err).Should(Say(deprecationTemplate, "--route-path"))
    89  			})
    90  		})
    91  	})
    92  
    93  	When("with a legacy (no applications section) manifest", func() {
    94  		var (
    95  			pathToManifest string // Can be a filepath or a directory with a manifest.
    96  		)
    97  
    98  		BeforeEach(func() {
    99  			tmpFile, err := ioutil.TempFile("", "manifest.yml")
   100  			Expect(err).ToNot(HaveOccurred())
   101  			pathToManifest = tmpFile.Name()
   102  			Expect(tmpFile.Close()).ToNot(HaveOccurred())
   103  		})
   104  
   105  		AfterEach(func() {
   106  			Expect(os.Remove(pathToManifest)).ToNot(HaveOccurred())
   107  		})
   108  
   109  		BeforeEach(func() {
   110  			helpers.WriteManifest(pathToManifest, map[string]interface{}{
   111  				"host": "blatz" + helpers.NewHostName(),
   112  			})
   113  		})
   114  		JustBeforeEach(func() {
   115  			helpers.WithHelloWorldApp(func(dir string) {
   116  				allArgs := []string{PushCommandName, appName, "-f", pathToManifest, "--no-start"}
   117  				allArgs = append(allArgs, localArgs...)
   118  				session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, allArgs...)
   119  				Eventually(session).Should(Exit(0))
   120  			})
   121  		})
   122  		JustAfterEach(func() {
   123  			Expect(session.Err).Should(Say(legacyManifestDeprecationTemplate))
   124  		})
   125  
   126  		When("no deprecated flags are provided", func() {
   127  			BeforeEach(func() {
   128  				localArgs = []string{}
   129  			})
   130  			It("does not output a deprecation warning", func() {
   131  				Expect(string(session.Err.Contents())).ToNot(ContainSubstring("command-line flag option is deprecated in favor of the 'routes' property in the manifest"))
   132  			})
   133  		})
   134  
   135  		When("the -d (domains) flag is provided", func() {
   136  			BeforeEach(func() {
   137  				localArgs = []string{"-d", privateDomain}
   138  			})
   139  			It("outputs a deprecation warning", func() {
   140  				Expect(session.Err).Should(Say(deprecationTemplate, "-d"))
   141  			})
   142  		})
   143  
   144  		When("the --hostname flag is provided", func() {
   145  			BeforeEach(func() {
   146  				localArgs = []string{"--hostname", host}
   147  			})
   148  			It("outputs a deprecation warning", func() {
   149  				Expect(session.Err).Should(Say(deprecationTemplate, "--hostname"))
   150  			})
   151  		})
   152  
   153  		When("the --no-hostname flag is provided", func() {
   154  			BeforeEach(func() {
   155  				localArgs = []string{"--no-hostname", "-d", privateDomain}
   156  			})
   157  			It("outputs a deprecation warning", func() {
   158  				Expect(session.Err).Should(Say(deprecationTemplate, "--no-hostname"))
   159  			})
   160  		})
   161  
   162  		When("the --route-path flag is provided", func() {
   163  			BeforeEach(func() {
   164  				localArgs = []string{"--route-path", "some-path"}
   165  			})
   166  			It("outputs a deprecation warning", func() {
   167  				Expect(session.Err).Should(Say(deprecationTemplate, "--route-path"))
   168  			})
   169  		})
   170  	})
   171  
   172  })