github.com/everlongproject/i18n4go@v0.2.7-0.20201028180611-670cbaceaa6b/integration/extract_strings/d_option_test.go (about) 1 package extract_strings_test 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "strings" 8 9 . "github.com/Liam-Williams/i18n4go/integration/test_helpers" 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("extract-strings -d dirName", func() { 15 var ( 16 fixturesPath string 17 inputFilesPath string 18 expectedFilesPath string 19 outputPath string 20 ) 21 22 BeforeEach(func() { 23 _, err := os.Getwd() 24 Ω(err).ShouldNot(HaveOccurred()) 25 26 outputPath, err = ioutil.TempDir("", "i18n4go4go") 27 Ω(err).ToNot(HaveOccurred()) 28 29 fixturesPath = filepath.Join("..", "..", "test_fixtures", "extract_strings") 30 inputFilesPath = filepath.Join(fixturesPath, "d_option", "input_files", "quota") 31 expectedFilesPath = filepath.Join(fixturesPath, "d_option", "expected_output") 32 }) 33 34 AfterEach(func() { 35 os.RemoveAll(outputPath) 36 }) 37 38 Context("When i18n4go4go is run with the -d flag", func() { 39 BeforeEach(func() { 40 session := Runi18n("-c", "extract-strings", "-v", "--po", "--meta", "-d", inputFilesPath, "-o", outputPath, "--ignore-regexp", "^[.]\\w+.go$") 41 42 Ω(session.ExitCode()).Should(Equal(0)) 43 }) 44 45 It("Walks input directory and compares each group of generated output to expected output", func() { 46 filepath.Walk(inputFilesPath, func(path string, info os.FileInfo, err error) error { 47 if info.IsDir() { 48 return nil 49 } 50 51 CompareExpectedToGeneratedTraslationJson( 52 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 53 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 54 ) 55 56 CompareExpectedToGeneratedPo( 57 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 58 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 59 ) 60 61 return nil 62 }) 63 }) 64 }) 65 66 Context("When i18n4go4go is run with the -d -r flags", func() { 67 BeforeEach(func() { 68 inputFilesPath = filepath.Join(inputFilesPath, "..") 69 70 session := Runi18n("-c", "extract-strings", "-v", "--po", "--meta", "-d", inputFilesPath, "-o", outputPath, "-r", "--ignore-regexp", "^[.]\\w+.go$") 71 Ω(session.ExitCode()).Should(Equal(0)) 72 }) 73 74 It("Walks input directories and compares each group of generated output to expected output", func() { 75 filepath.Walk(inputFilesPath, func(path string, info os.FileInfo, err error) error { 76 if info.IsDir() { 77 return nil 78 } 79 80 CompareExpectedToGeneratedTraslationJson( 81 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 82 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 83 ) 84 85 CompareExpectedToGeneratedPo( 86 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 87 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 88 ) 89 90 return nil 91 }) 92 }) 93 }) 94 })