github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+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  
    28  			rawConfig := fmt.Sprintf(`{"Locale":"%s", "ConfigVersion": %d }`, configVal, CurrentConfigVersion)
    29  			setConfig(homeDir, rawConfig)
    30  
    31  			defer os.Unsetenv("LANG")
    32  			if langVal == "" {
    33  				os.Unsetenv("LANG")
    34  			} else {
    35  				os.Setenv("LANG", langVal)
    36  			}
    37  
    38  			defer os.Unsetenv("LC_ALL")
    39  			if lcAllVall == "" {
    40  				os.Unsetenv("LC_ALL")
    41  			} else {
    42  				os.Setenv("LC_ALL", lcAllVall)
    43  			}
    44  
    45  			config, err := LoadConfig()
    46  			Expect(err).ToNot(HaveOccurred())
    47  			Expect(config).ToNot(BeNil())
    48  
    49  			Expect(config.Locale()).To(Equal(expected))
    50  		},
    51  
    52  		Entry("LANG=ko-KO.UTF-8 LC_ALL=empty       config=empty ko-KO", "ko-KO.UTF-8", "", "", "ko-KO"),
    53  		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"),
    54  		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"),
    55  
    56  		Entry("config=empty LANG=empty       LC_ALL=empty       default", "", "", "", DefaultLocale),
    57  	)
    58  })