github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/util/configv3/locale_test.go (about)

     1  package configv3_test
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	. "code.cloudfoundry.org/cli/util/configv3"
     8  
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/ginkgo/extensions/table"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Config", func() {
    15  	var homeDir string
    16  
    17  	BeforeEach(func() {
    18  		homeDir = setup()
    19  	})
    20  
    21  	AfterEach(func() {
    22  		teardown(homeDir)
    23  	})
    24  
    25  	DescribeTable("Locale",
    26  		func(langVal string, lcAllVall string, configVal string, expected string) {
    27  			rawConfig := fmt.Sprintf(`{"Locale":"%s"}`, configVal)
    28  			setConfig(homeDir, rawConfig)
    29  
    30  			defer os.Unsetenv("LANG")
    31  			if langVal == "" {
    32  				os.Unsetenv("LANG")
    33  			} else {
    34  				os.Setenv("LANG", langVal)
    35  			}
    36  
    37  			defer os.Unsetenv("LC_ALL")
    38  			if lcAllVall == "" {
    39  				os.Unsetenv("LC_ALL")
    40  			} else {
    41  				os.Setenv("LC_ALL", lcAllVall)
    42  			}
    43  
    44  			config, err := LoadConfig()
    45  			Expect(err).ToNot(HaveOccurred())
    46  			Expect(config).ToNot(BeNil())
    47  
    48  			Expect(config.Locale()).To(Equal(expected))
    49  		},
    50  
    51  		Entry("LANG=ko-KO.UTF-8 LC_ALL=empty       config=empty ko-KO", "ko-KO.UTF-8", "", "", "ko-KO"),
    52  		Entry("LANG=ko-KO.UTF-8 LC_ALL=fr_FR.UTF-8 config=empty fr-FR", "ko-KO.UTF-8", "fr_FR.UTF-8", "", "fr-FR"),
    53  		Entry("LANG=ko-KO.UTF-8 LC_ALL=fr_FR.UTF-8 config=pt-BR pt-BR", "ko-KO.UTF-8", "fr_FR.UTF-8", "pt-BR", "pt-BR"),
    54  
    55  		Entry("config=empty LANG=empty       LC_ALL=empty       default", "", "", "", DefaultLocale),
    56  	)
    57  })