github.com/arunkumar7540/cli@v6.45.0+incompatible/util/configv3/env_test.go (about) 1 package configv3_test 2 3 import ( 4 "time" 5 6 . "code.cloudfoundry.org/cli/util/configv3" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/ginkgo/extensions/table" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("Config", func() { 14 var ( 15 config *Config 16 ) 17 18 BeforeEach(func() { 19 config = &Config{} 20 }) 21 22 When("there are environment variables set", func() { 23 BeforeEach(func() { 24 config.ENV = EnvOverride{ 25 CFDialTimeout: "1234", 26 CFPassword: "I am password.", 27 CFStagingTimeout: "8675", 28 CFStartupTimeout: "309", 29 CFUsername: "i-R-user", 30 DockerPassword: "banana", 31 HTTPSProxy: "proxy.com", 32 } 33 }) 34 35 It("overrides specific config values using those variables", func() { 36 Expect(config.CFUsername()).To(Equal("i-R-user")) 37 Expect(config.CFPassword()).To(Equal("I am password.")) 38 Expect(config.DialTimeout()).To(Equal(1234 * time.Second)) 39 Expect(config.DockerPassword()).To(Equal("banana")) 40 Expect(config.HTTPSProxy()).To(Equal("proxy.com")) 41 Expect(config.StagingTimeout()).To(Equal(time.Duration(8675) * time.Minute)) 42 Expect(config.StartupTimeout()).To(Equal(time.Duration(309) * time.Minute)) 43 }) 44 }) 45 46 Describe("BinaryName", func() { 47 BeforeEach(func() { 48 config.ENV.BinaryName = "potatoman" 49 }) 50 51 It("returns the name used to invoke", func() { 52 Expect(config.BinaryName()).To(Equal("potatoman")) 53 }) 54 }) 55 56 Describe("BinaryVersion", func() { 57 It("returns back version.BinaryVersion", func() { 58 conf := Config{} 59 Expect(conf.BinaryVersion()).To(Equal("0.0.0-unknown-version")) 60 }) 61 }) 62 63 Describe("DialTimeout", func() { 64 When("no DialTimeout is set in the env", func() { 65 BeforeEach(func() { 66 config.ENV.CFDialTimeout = "" 67 }) 68 69 It("uses the default dial timeout", func() { 70 Expect(config.DialTimeout()).To(Equal(DefaultDialTimeout)) 71 }) 72 }) 73 }) 74 75 DescribeTable("Experimental", 76 func(envVal string, expected bool) { 77 config.ENV.Experimental = envVal 78 Expect(config.Experimental()).To(Equal(expected)) 79 }, 80 81 Entry("uses default value of false if environment value is not set", "", false), 82 Entry("uses environment value if a valid environment value is set", "true", true), 83 Entry("uses default value of false if an invalid environment value is set", "something-invalid", false), 84 ) 85 86 DescribeTable("ExperimentalLogin", 87 func(envVal string, expected bool) { 88 config.ENV.ExperimentalLogin = envVal 89 Expect(config.ExperimentalLogin()).To(Equal(expected)) 90 }, 91 92 Entry("uses default value of false if environment value is not set", "", false), 93 Entry("uses environment value if a valid environment value is set", "true", true), 94 Entry("uses default value of false if an invalid environment value is set", "something-invalid", false), 95 ) 96 97 DescribeTable("LogLevel", 98 func(envVal string, expectedLevel int) { 99 config := Config{ENV: EnvOverride{CFLogLevel: envVal}} 100 Expect(config.LogLevel()).To(Equal(expectedLevel)) 101 }, 102 103 Entry("Default to 0", "", 0), 104 Entry("panic returns 0", "panic", 0), 105 Entry("fatal returns 1", "fatal", 1), 106 Entry("error returns 2", "error", 2), 107 Entry("warn returns 3", "warn", 3), 108 Entry("info returns 4", "info", 4), 109 Entry("debug returns 5", "debug", 5), 110 Entry("dEbUg returns 5", "dEbUg", 5), 111 ) 112 113 Describe("StagingTimeout", func() { 114 When("no StagingTimeout is set in the env", func() { 115 BeforeEach(func() { 116 config.ENV.CFStagingTimeout = "" 117 }) 118 119 It("uses the default staging timeout", func() { 120 Expect(config.StagingTimeout()).To(Equal(DefaultStagingTimeout)) 121 }) 122 }) 123 }) 124 125 Describe("StartupTimeout", func() { 126 When("no StartupTimeout is set in the env", func() { 127 BeforeEach(func() { 128 config.ENV.CFStartupTimeout = "" 129 }) 130 131 It("uses the default startup timeout", func() { 132 Expect(config.StartupTimeout()).To(Equal(DefaultStartupTimeout)) 133 }) 134 }) 135 }) 136 })