github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/util/configv3/color_test.go (about) 1 package configv3_test 2 3 import ( 4 "fmt" 5 "os" 6 7 . "code.cloudfoundry.org/cli/util/configv3" 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 homeDir string 15 16 BeforeEach(func() { 17 homeDir = setup() 18 }) 19 20 AfterEach(func() { 21 teardown(homeDir) 22 }) 23 24 DescribeTable("ColorEnabled", 25 func(configVal string, envVal string, expected ColorSetting) { 26 rawConfig := fmt.Sprintf(`{"ColorEnabled":"%s", "ConfigVersion": %d }`, configVal, CurrentConfigVersion) 27 setConfig(homeDir, rawConfig) 28 29 defer os.Unsetenv("CF_COLOR") 30 if envVal == "" { 31 os.Unsetenv("CF_COLOR") 32 } else { 33 os.Setenv("CF_COLOR", envVal) 34 } 35 36 config, err := LoadConfig() 37 Expect(err).ToNot(HaveOccurred()) 38 Expect(config).ToNot(BeNil()) 39 40 Expect(config.ColorEnabled()).To(Equal(expected)) 41 }, 42 Entry("config=true env=true enabled", "true", "true", ColorEnabled), 43 Entry("config=true env=false disabled", "true", "false", ColorDisabled), 44 Entry("config=false env=true enabled", "false", "true", ColorEnabled), 45 Entry("config=false env=false disabled", "false", "false", ColorDisabled), 46 47 Entry("config=unset env=false disabled", "", "false", ColorDisabled), 48 Entry("config=unset env=true enabled", "", "true", ColorEnabled), 49 Entry("config=false env=unset disabled", "false", "", ColorDisabled), 50 Entry("config=true env=unset disabled", "true", "", ColorEnabled), 51 52 Entry("config=unset env=unset falls back to default", "", "", ColorAuto), 53 ) 54 })