github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/global/env_command_test.go (about)

     1  package global
     2  
     3  import (
     4  	"fmt"
     5  	"math/rand"
     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("env command", func() {
    15  	var (
    16  		appName string
    17  		orgName string
    18  
    19  		key1 string
    20  		key2 string
    21  		key3 string
    22  		key4 string
    23  		key5 string
    24  		key6 string
    25  
    26  		val1 string
    27  		val2 int
    28  		val3 string
    29  		val4 int
    30  		val5 string
    31  		val6 string
    32  	)
    33  
    34  	BeforeEach(func() {
    35  		spaceName := helpers.NewSpaceName()
    36  		orgName = helpers.NewOrgName()
    37  		helpers.SetupCF(orgName, spaceName)
    38  
    39  		appName = helpers.PrefixedRandomName("app")
    40  
    41  		key1 = helpers.PrefixedRandomName("key1")
    42  		key2 = helpers.PrefixedRandomName("key2")
    43  		val1 = helpers.PrefixedRandomName("val1")
    44  		val2 = rand.Intn(2000)
    45  		json := fmt.Sprintf(`{"%s":"%s", "%s":%d}`, key1, val1, key2, val2)
    46  		session := helpers.CF("set-staging-environment-variable-group", json)
    47  		Eventually(session).Should(Exit(0))
    48  
    49  		key3 = helpers.PrefixedRandomName("key3")
    50  		key4 = helpers.PrefixedRandomName("key4")
    51  		val3 = helpers.PrefixedRandomName("val3")
    52  		val4 = rand.Intn(2000)
    53  		json = fmt.Sprintf(`{"%s":"%s", "%s":%d}`, key3, val3, key4, val4)
    54  		session = helpers.CF("set-running-environment-variable-group", json)
    55  		Eventually(session).Should(Exit(0))
    56  
    57  		helpers.WithHelloWorldApp(func(appDir string) {
    58  			Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-route")).Should(Exit(0))
    59  		})
    60  
    61  		key5 = helpers.PrefixedRandomName("key5")
    62  		key6 = helpers.PrefixedRandomName("key6")
    63  		val5 = helpers.PrefixedRandomName("val5")
    64  		val6 = fmt.Sprint(rand.Intn(2000))
    65  		session = helpers.CF("set-env", appName, key5, val5)
    66  		Eventually(session).Should(Exit(0))
    67  		session = helpers.CF("set-env", appName, key6, val6)
    68  		Eventually(session).Should(Exit(0))
    69  	})
    70  
    71  	AfterEach(func() {
    72  		session := helpers.CF("set-staging-environment-variable-group", "{}")
    73  		Eventually(session).Should(Exit(0))
    74  		session = helpers.CF("set-running-environment-variable-group", "{}")
    75  		Eventually(session).Should(Exit(0))
    76  
    77  		helpers.QuickDeleteOrg(orgName)
    78  	})
    79  
    80  	It("displays all environment variables", func() {
    81  		session := helpers.CF("env", appName)
    82  
    83  		Eventually(session).Should(Say("System-Provided:"))
    84  		Eventually(session).Should(Say("VCAP_APPLICATION"))
    85  
    86  		Eventually(session).Should(Say("User-Provided:"))
    87  		Eventually(session).Should(Say("%s: %s", key5, val5))
    88  		Eventually(session).Should(Say("%s: %s", key6, val6))
    89  
    90  		Eventually(session).Should(Say("Running Environment Variable Groups:"))
    91  		Eventually(session).Should(Say("%s: %s", key3, val3))
    92  		Eventually(session).Should(Say("%s: %d", key4, val4))
    93  
    94  		Eventually(session).Should(Say("Staging Environment Variable Groups:"))
    95  		Eventually(session).Should(Say("%s: %s", key1, val1))
    96  		Eventually(session).Should(Say("%s: %d", key2, val2))
    97  
    98  		Eventually(session).Should(Exit(0))
    99  	})
   100  })