github.com/CharukaK/i18n4go@v0.6.0/integration/extract_strings/f_o_options_test.go (about) 1 // Copyright © 2015-2023 The Knative Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package extract_strings_test 16 17 import ( 18 "io/ioutil" 19 "os" 20 "path/filepath" 21 22 . "github.com/CharukaK/i18n4go/integration/test_helpers" 23 . "github.com/onsi/ginkgo" 24 . "github.com/onsi/gomega" 25 ) 26 27 var _ = Describe("extract-strings -f fileName -o outputDir", func() { 28 var ( 29 fixturesPath string 30 inputFilesPath string 31 expectedFilesPath string 32 outputPath string 33 ) 34 35 BeforeEach(func() { 36 _, err := os.Getwd() 37 Ω(err).ShouldNot(HaveOccurred()) 38 39 fixturesPath = filepath.Join("..", "..", "test_fixtures", "extract_strings", "f_option") 40 inputFilesPath = filepath.Join(fixturesPath, "input_files") 41 expectedFilesPath = filepath.Join(fixturesPath, "expected_output") 42 }) 43 44 BeforeEach(func() { 45 var err error 46 outputPath, err = ioutil.TempDir("", "i18n4go4go") 47 Ω(err).ToNot(HaveOccurred()) 48 }) 49 50 AfterEach(func() { 51 os.RemoveAll(outputPath) 52 }) 53 Context("Using legacy commands", func() { 54 Context("-o outputDir --output-flat (default)", func() { 55 BeforeEach(func() { 56 session := Runi18n("-c", "extract-strings", "-v", "--po", "--meta", "-f", filepath.Join(inputFilesPath, "app.go"), "-o", outputPath) 57 Ω(session.ExitCode()).Should(Equal(0)) 58 }) 59 60 It("Walks input directory and compares each group of generated output to expected output", func() { 61 62 CompareExpectedToGeneratedTraslationJson( 63 filepath.Join(expectedFilesPath, "app.go.en.json"), 64 filepath.Join(outputPath, "app.go.en.json"), 65 ) 66 67 CompareExpectedToGeneratedExtendedJson( 68 filepath.Join(expectedFilesPath, "app.go.extracted.json"), 69 filepath.Join(outputPath, "app.go.extracted.json"), 70 ) 71 72 CompareExpectedToGeneratedPo( 73 filepath.Join(expectedFilesPath, "app.go.en.po"), 74 filepath.Join(outputPath, "app.go.en.po"), 75 ) 76 }) 77 }) 78 79 Context("-o outputDir --output-match-package", func() { 80 BeforeEach(func() { 81 session := Runi18n("-c", "extract-strings", "-v", "--po", "--meta", "-f", filepath.Join(inputFilesPath, "app.go"), "-o", outputPath, "--output-match-package") 82 Ω(session.ExitCode()).Should(Equal(0)) 83 }) 84 85 It("Walks input directory and compares each group of generated output to expected output and package subdirectories", func() { 86 expectedFilesPath = filepath.Join(expectedFilesPath, "app") 87 outputPath = filepath.Join(outputPath, "app") 88 CompareExpectedToGeneratedTraslationJson( 89 filepath.Join(expectedFilesPath, "app.go.en.json"), 90 filepath.Join(outputPath, "app.go.en.json"), 91 ) 92 93 CompareExpectedToGeneratedExtendedJson( 94 filepath.Join(expectedFilesPath, "app.go.extracted.json"), 95 filepath.Join(outputPath, "app.go.extracted.json"), 96 ) 97 98 CompareExpectedToGeneratedPo( 99 filepath.Join(expectedFilesPath, "app.go.en.po"), 100 filepath.Join(outputPath, "app.go.en.po"), 101 ) 102 }) 103 }) 104 105 }) 106 107 Context("Using cobra commands", func() { 108 Context("-o outputDir --output-flat (default)", func() { 109 BeforeEach(func() { 110 session := Runi18n("extract-strings", "-v", "--po", "--meta", "-f", filepath.Join(inputFilesPath, "app.go"), "-o", outputPath) 111 Ω(session.ExitCode()).Should(Equal(0)) 112 }) 113 114 It("Walks input directory and compares each group of generated output to expected output", func() { 115 116 CompareExpectedToGeneratedTraslationJson( 117 filepath.Join(expectedFilesPath, "app.go.en.json"), 118 filepath.Join(outputPath, "app.go.en.json"), 119 ) 120 121 CompareExpectedToGeneratedExtendedJson( 122 filepath.Join(expectedFilesPath, "app.go.extracted.json"), 123 filepath.Join(outputPath, "app.go.extracted.json"), 124 ) 125 126 CompareExpectedToGeneratedPo( 127 filepath.Join(expectedFilesPath, "app.go.en.po"), 128 filepath.Join(outputPath, "app.go.en.po"), 129 ) 130 }) 131 }) 132 133 Context("-o outputDir --output-match-package", func() { 134 BeforeEach(func() { 135 session := Runi18n("extract-strings", "-v", "--po", "--meta", "-f", filepath.Join(inputFilesPath, "app.go"), "-o", outputPath, "--output-match-package") 136 Ω(session.ExitCode()).Should(Equal(0)) 137 }) 138 139 It("Walks input directory and compares each group of generated output to expected output and package subdirectories", func() { 140 expectedFilesPath = filepath.Join(expectedFilesPath, "app") 141 outputPath = filepath.Join(outputPath, "app") 142 CompareExpectedToGeneratedTraslationJson( 143 filepath.Join(expectedFilesPath, "app.go.en.json"), 144 filepath.Join(outputPath, "app.go.en.json"), 145 ) 146 147 CompareExpectedToGeneratedExtendedJson( 148 filepath.Join(expectedFilesPath, "app.go.extracted.json"), 149 filepath.Join(outputPath, "app.go.extracted.json"), 150 ) 151 152 CompareExpectedToGeneratedPo( 153 filepath.Join(expectedFilesPath, "app.go.en.po"), 154 filepath.Join(outputPath, "app.go.en.po"), 155 ) 156 }) 157 }) 158 159 }) 160 })