github.com/Liam-Williams/i18n4go@v0.2.7-0.20201028180611-670cbaceaa6b/integration/extract_strings/f_o_options_test.go (about) 1 package extract_strings_test 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 8 . "github.com/Liam-Williams/i18n4go/integration/test_helpers" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("extract-strings -f fileName -o outputDir", func() { 14 var ( 15 fixturesPath string 16 inputFilesPath string 17 expectedFilesPath string 18 outputPath string 19 ) 20 21 BeforeEach(func() { 22 _, err := os.Getwd() 23 Ω(err).ShouldNot(HaveOccurred()) 24 25 fixturesPath = filepath.Join("..", "..", "test_fixtures", "extract_strings", "f_option") 26 inputFilesPath = filepath.Join(fixturesPath, "input_files") 27 expectedFilesPath = filepath.Join(fixturesPath, "expected_output") 28 }) 29 30 BeforeEach(func() { 31 var err error 32 outputPath, err = ioutil.TempDir("", "i18n4go4go") 33 Ω(err).ToNot(HaveOccurred()) 34 }) 35 36 AfterEach(func() { 37 os.RemoveAll(outputPath) 38 }) 39 40 Context("-o outputDir --output-flat (default)", func() { 41 BeforeEach(func() { 42 session := Runi18n("-c", "extract-strings", "-v", "--po", "--meta", "-f", filepath.Join(inputFilesPath, "app.go"), "-o", outputPath) 43 Ω(session.ExitCode()).Should(Equal(0)) 44 }) 45 46 It("Walks input directory and compares each group of generated output to expected output", func() { 47 48 CompareExpectedToGeneratedTraslationJson( 49 filepath.Join(expectedFilesPath, "app.go.en.json"), 50 filepath.Join(outputPath, "app.go.en.json"), 51 ) 52 53 CompareExpectedToGeneratedExtendedJson( 54 filepath.Join(expectedFilesPath, "app.go.extracted.json"), 55 filepath.Join(outputPath, "app.go.extracted.json"), 56 ) 57 58 CompareExpectedToGeneratedPo( 59 filepath.Join(expectedFilesPath, "app.go.en.po"), 60 filepath.Join(outputPath, "app.go.en.po"), 61 ) 62 }) 63 }) 64 65 Context("-o outputDir --output-match-package", func() { 66 BeforeEach(func() { 67 session := Runi18n("-c", "extract-strings", "-v", "--po", "--meta", "-f", filepath.Join(inputFilesPath, "app.go"), "-o", outputPath, "--output-match-package") 68 Ω(session.ExitCode()).Should(Equal(0)) 69 }) 70 71 It("Walks input directory and compares each group of generated output to expected output and package subdirectories", func() { 72 expectedFilesPath = filepath.Join(expectedFilesPath, "app") 73 outputPath = filepath.Join(outputPath, "app") 74 CompareExpectedToGeneratedTraslationJson( 75 filepath.Join(expectedFilesPath, "app.go.en.json"), 76 filepath.Join(outputPath, "app.go.en.json"), 77 ) 78 79 CompareExpectedToGeneratedExtendedJson( 80 filepath.Join(expectedFilesPath, "app.go.extracted.json"), 81 filepath.Join(outputPath, "app.go.extracted.json"), 82 ) 83 84 CompareExpectedToGeneratedPo( 85 filepath.Join(expectedFilesPath, "app.go.en.po"), 86 filepath.Join(outputPath, "app.go.en.po"), 87 ) 88 }) 89 }) 90 })