github.com/sleungcy/cli@v7.1.0+incompatible/integration/v7/isolated/config_command_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"strings"
     5  
     6  	"code.cloudfoundry.org/cli/integration/helpers"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/ginkgo/extensions/table"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("config command", func() {
    15  	var helpText func(session *Session)
    16  
    17  	BeforeEach(func() {
    18  		helpText = func(session *Session) {
    19  			Eventually(session).Should(Say(`NAME:`))
    20  			Eventually(session).Should(Say(`config - Write default values to the config`))
    21  			Eventually(session).Should(Say("USAGE:"))
    22  			Eventually(session).Should(Say(`cf config \[--async-timeout TIMEOUT_IN_MINUTES\] \[--trace \(true | false | path/to/file\)\] \[--color \(true | false\)\] \[--locale \(LOCALE | CLEAR\)\]`))
    23  			Eventually(session).Should(Say("OPTIONS:"))
    24  			Eventually(session).Should(Say(`--async-timeout\s+Timeout in minutes for async HTTP requests`))
    25  			Eventually(session).Should(Say(`--color\s+Enable or disable color in CLI output`))
    26  			Eventually(session).Should(Say(`--locale\s+Set default locale. If LOCALE is 'CLEAR', previous locale is deleted.`))
    27  			Eventually(session).Should(Say(`--trace\s+Trace HTTP requests by default. If a file path is provided then output will write to the file provided. If the file does not exist it will be created.`))
    28  		}
    29  	})
    30  
    31  	Describe("help", func() {
    32  		When("--help flag is set", func() {
    33  			It("shows the help text", func() {
    34  				session := helpers.CF("config", "--help")
    35  				helpText(session)
    36  				Eventually(session).Should(Exit(0))
    37  			})
    38  		})
    39  	})
    40  
    41  	Context("when no flags are given", func() {
    42  		It("returns an error and displays the help text", func() {
    43  			session := helpers.CF("config")
    44  			Eventually(session.Err).Should(Say("Incorrect Usage: at least one flag must be provided"))
    45  			helpText(session)
    46  			Eventually(session).Should(Exit(1))
    47  		})
    48  	})
    49  
    50  	DescribeTable("allows setting async timeout to",
    51  		func(timeout string) {
    52  			session := helpers.CF("config", "--async-timeout", timeout)
    53  			Eventually(session).Should(Say(`Setting values in config\.\.\.`))
    54  			Eventually(session).Should(Say("OK"))
    55  			Eventually(session).Should(Exit(0))
    56  		},
    57  
    58  		Entry("integer", "10"),
    59  	)
    60  
    61  	When("the timeout provided is not an integer", func() {
    62  		It("fails with the appropriate errors", func() {
    63  			session := helpers.CF("config", "--async-timeout", "ten-seconds")
    64  			Eventually(session.Err).Should(Say("Incorrect Usage: Timeout must be an integer greater than or equal to 1"))
    65  			helpText(session)
    66  			Eventually(session).Should(Exit(1))
    67  		})
    68  	})
    69  
    70  	When("the timeout provided is 0 or less", func() {
    71  		It("fails with the appropriate errors", func() {
    72  			session := helpers.CF("config", "--async-timeout", "0")
    73  			Eventually(session.Err).Should(Say("Incorrect Usage: Timeout must be an integer greater than or equal to 1"))
    74  			helpText(session)
    75  			Eventually(session).Should(Exit(1))
    76  		})
    77  	})
    78  
    79  	DescribeTable("allows setting color to",
    80  		func(color string) {
    81  			session := helpers.CF("config", "--color", color)
    82  			Eventually(session).Should(Exit(0))
    83  		},
    84  
    85  		Entry("true", "true"),
    86  		Entry("false", "false"),
    87  	)
    88  
    89  	When("the color argument provided is not a boolean", func() {
    90  		It("fails with the appropriate errors", func() {
    91  			session := helpers.CF("config", "--color", "Teal")
    92  			Eventually(session.Err).Should(Say("Incorrect Usage: COLOR must be \"true\" or \"false\""))
    93  			helpText(session)
    94  			Eventually(session).Should(Exit(1))
    95  		})
    96  	})
    97  
    98  	DescribeTable("allows setting locale to",
    99  		func(locale string) {
   100  			session := helpers.CF("config", "--locale", locale)
   101  			Eventually(session).Should(Exit(0))
   102  
   103  			underscored_locale := strings.Replace(locale, "-", "_", -1)
   104  			session = helpers.CF("config", "--locale", underscored_locale)
   105  			Eventually(session).Should(Exit(0))
   106  		},
   107  
   108  		Entry("Chinese (Simplified)", "zh-Hans"),
   109  		Entry("Chinese (Traditional)", "zh-Hant"),
   110  		Entry("English (United States)", "en-US"),
   111  		Entry("French", "fr-FR"),
   112  		Entry("German", "de-DE"),
   113  		Entry("Italian", "it-IT"),
   114  		Entry("Japanese", "ja-JP"),
   115  		Entry("Korean", "ko-KR"),
   116  		Entry("Portuguese (Brazil)", "pt-BR"),
   117  		Entry("Spanish", "es-ES"),
   118  		Entry("CLEAR", "CLEAR"),
   119  	)
   120  
   121  	When("the locale provided is not a valid option", func() {
   122  		It("fails with the appropriate errors", func() {
   123  			session := helpers.CF("config", "--locale", "bora bora")
   124  			Eventually(session.Err).Should(Say("Incorrect Usage: LOCALE must be CLEAR, de-DE, en-US, es-ES, fr-FR, it-IT, ja-JP, ko-KR, pt-BR, zh-Hans, zh-Hant"))
   125  			helpText(session)
   126  			Eventually(session).Should(Exit(1))
   127  		})
   128  	})
   129  
   130  	DescribeTable("allows setting trace to",
   131  		func(trace string) {
   132  			session := helpers.CF("config", "--trace", trace)
   133  			Eventually(session).Should(Exit(0))
   134  		},
   135  
   136  		Entry("true", "true"),
   137  		Entry("false", "false"),
   138  		Entry("path", "some/path"),
   139  	)
   140  })