github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/util/configv3/config_windows_test.go (about)

     1  // +build windows
     2  
     3  package configv3_test
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"path/filepath"
     9  
    10  	. "code.cloudfoundry.org/cli/util/configv3"
    11  
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/ginkgo/extensions/table"
    14  	. "github.com/onsi/gomega"
    15  )
    16  
    17  var _ = Describe("Verbose", func() {
    18  	var homeDir string
    19  
    20  	BeforeEach(func() {
    21  		homeDir = setup()
    22  	})
    23  
    24  	AfterEach(func() {
    25  		teardown(homeDir)
    26  	})
    27  
    28  	DescribeTable("absolute paths",
    29  		func(env string, configTrace string, flag bool, expected bool, location []string) {
    30  			rawConfig := fmt.Sprintf(`{ "Trace":"%s", "ConfigVersion": %d }`, configTrace, CurrentConfigVersion)
    31  			setConfig(homeDir, rawConfig)
    32  
    33  			defer os.Unsetenv("CF_TRACE")
    34  			if env == "" {
    35  				Expect(os.Unsetenv("CF_TRACE")).ToNot(HaveOccurred())
    36  			} else {
    37  				Expect(os.Setenv("CF_TRACE", env)).ToNot(HaveOccurred())
    38  			}
    39  
    40  			config, err := LoadConfig(FlagOverride{
    41  				Verbose: flag,
    42  			})
    43  			Expect(err).ToNot(HaveOccurred())
    44  			Expect(config).ToNot(BeNil())
    45  
    46  			verbose, parsedLocation := config.Verbose()
    47  			Expect(verbose).To(Equal(expected))
    48  			Expect(parsedLocation).To(Equal(location))
    49  		},
    50  
    51  		Entry("CF_TRACE true: enables verbose", "true", "", false, true, nil),
    52  		Entry("CF_TRACE true, config trace false: enables verbose", "true", "false", false, true, nil),
    53  		Entry("CF_TRACE true, config trace file path: enables verbose AND logging to file", "true", "C:\\\\foo\\\\bar", false, true, []string{"C:\\foo\\bar"}),
    54  
    55  		Entry("CF_TRACE false: disables verbose", "false", "", false, false, nil),
    56  		Entry("CF_TRACE false, '-v': enables verbose", "false", "", true, true, nil),
    57  		Entry("CF_TRACE false, config trace true: disables verbose", "false", "true", false, false, nil),
    58  		Entry("CF_TRACE false, config trace file path: enables logging to file", "false", "C:\\\\foo\\\\bar", false, false, []string{"C:\\foo\\bar"}),
    59  		Entry("CF_TRACE false, config trace file path, '-v': enables verbose AND logging to file", "false", "C:\\\\foo\\\\bar", true, true, []string{"C:\\foo\\bar"}),
    60  
    61  		Entry("CF_TRACE empty: disables verbose", "", "", false, false, nil),
    62  		Entry("CF_TRACE empty:, '-v': enables verbose", "", "", true, true, nil),
    63  		Entry("CF_TRACE empty, config trace true: enables verbose", "", "true", false, true, nil),
    64  		Entry("CF_TRACE empty, config trace file path: enables logging to file", "", "C:\\\\foo\\\\bar", false, false, []string{"C:\\foo\\bar"}),
    65  		Entry("CF_TRACE empty, config trace file path, '-v': enables verbose AND logging to file", "", "C:\\\\foo\\\\bar", true, true, []string{"C:\\foo\\bar"}),
    66  
    67  		Entry("CF_TRACE filepath: enables logging to file", "C:\\foo\\bar", "", false, false, []string{"C:\\foo\\bar"}),
    68  		Entry("CF_TRACE filepath, '-v': enables logging to file", "C:\\foo\\bar", "", true, true, []string{"C:\\foo\\bar"}),
    69  		Entry("CF_TRACE filepath, config trace true: enables verbose AND logging to file", "C:\\foo\\bar", "true", false, true, []string{"C:\\foo\\bar"}),
    70  		Entry("CF_TRACE filepath, config trace filepath: enables logging to file for BOTH paths", "C:\\foo\\bar", "C:\\\\baz", false, false, []string{"C:\\foo\\bar", "C:\\baz"}),
    71  		Entry("CF_TRACE filepath, config trace filepath, '-v': enables verbose AND logging to file for BOTH paths", "C:\\foo\\bar", "C:\\\\baz", true, true, []string{"C:\\foo\\bar", "C:\\baz"}),
    72  	)
    73  
    74  	Context("relative paths (cannot be tested in DescribeTable)", func() {
    75  		It("resolves relative paths into absolute paths", func() {
    76  			configTrace := "foo/bar"
    77  			rawConfig := fmt.Sprintf(`{ "Trace":"%s", "ConfigVersion": %d  }`, configTrace, CurrentConfigVersion)
    78  			setConfig(homeDir, rawConfig)
    79  
    80  			cfTrace := "foo2\bar2"
    81  			Expect(os.Setenv("CF_TRACE", cfTrace)).ToNot(HaveOccurred())
    82  			defer os.Unsetenv("CF_TRACE")
    83  
    84  			config, err := LoadConfig(FlagOverride{})
    85  			Expect(err).ToNot(HaveOccurred())
    86  			Expect(config).ToNot(BeNil())
    87  
    88  			cwd, err := os.Getwd()
    89  			Expect(err).ToNot(HaveOccurred())
    90  			_, parsedLocation := config.Verbose()
    91  			Expect(parsedLocation).To(Equal([]string{filepath.Join(cwd, cfTrace), filepath.Join(cwd, configTrace)}))
    92  		})
    93  	})
    94  })