github.com/CharukaK/i18n4go@v0.6.0/integration/extract_strings/d_option_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 "strings" 22 23 . "github.com/CharukaK/i18n4go/integration/test_helpers" 24 . "github.com/onsi/ginkgo" 25 . "github.com/onsi/gomega" 26 ) 27 28 var _ = Describe("extract-strings -d dirName", func() { 29 var ( 30 fixturesPath string 31 inputFilesPath string 32 expectedFilesPath string 33 outputPath string 34 ) 35 36 BeforeEach(func() { 37 _, err := os.Getwd() 38 Ω(err).ShouldNot(HaveOccurred()) 39 40 outputPath, err = ioutil.TempDir("", "i18n4go4go") 41 Ω(err).ToNot(HaveOccurred()) 42 43 fixturesPath = filepath.Join("..", "..", "test_fixtures", "extract_strings") 44 inputFilesPath = filepath.Join(fixturesPath, "d_option", "input_files", "quota") 45 expectedFilesPath = filepath.Join(fixturesPath, "d_option", "expected_output") 46 }) 47 48 AfterEach(func() { 49 os.RemoveAll(outputPath) 50 }) 51 52 Context("Using legacy commands", func() { 53 Context("When i18n4go4go is run with the -d flag", func() { 54 BeforeEach(func() { 55 session := Runi18n("-c", "extract-strings", "-v", "--po", "--meta", "-d", inputFilesPath, "-o", outputPath, "--ignore-regexp", "^[.]\\w+.go$") 56 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 filepath.Walk(inputFilesPath, func(path string, info os.FileInfo, err error) error { 62 if info.IsDir() { 63 return nil 64 } 65 66 CompareExpectedToGeneratedTraslationJson( 67 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 68 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 69 ) 70 71 CompareExpectedToGeneratedPo( 72 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 73 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 74 ) 75 76 return nil 77 }) 78 }) 79 }) 80 81 Context("When i18n4go4go is run with the -d -r flags", func() { 82 BeforeEach(func() { 83 inputFilesPath = filepath.Join(inputFilesPath, "..") 84 85 session := Runi18n("-c", "extract-strings", "-v", "--po", "--meta", "-d", inputFilesPath, "-o", outputPath, "-r", "--ignore-regexp", "^[.]\\w+.go$") 86 Ω(session.ExitCode()).Should(Equal(0)) 87 }) 88 89 It("Walks input directories and compares each group of generated output to expected output", func() { 90 filepath.Walk(inputFilesPath, func(path string, info os.FileInfo, err error) error { 91 if info.IsDir() { 92 return nil 93 } 94 95 CompareExpectedToGeneratedTraslationJson( 96 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 97 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 98 ) 99 100 CompareExpectedToGeneratedPo( 101 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 102 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 103 ) 104 105 return nil 106 }) 107 }) 108 }) 109 110 }) 111 112 Context("Using cobra commands", func() { 113 Context("When i18n4go4go is run with the -d flag", func() { 114 BeforeEach(func() { 115 session := Runi18n("extract-strings", "-v", "--po", "--meta", "-d", inputFilesPath, "-o", outputPath, "--ignore-regexp", "^[.]\\w+.go$") 116 117 Ω(session.ExitCode()).Should(Equal(0)) 118 }) 119 120 It("Walks input directory and compares each group of generated output to expected output", func() { 121 filepath.Walk(inputFilesPath, func(path string, info os.FileInfo, err error) error { 122 if info.IsDir() { 123 return nil 124 } 125 126 CompareExpectedToGeneratedTraslationJson( 127 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 128 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 129 ) 130 131 CompareExpectedToGeneratedPo( 132 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 133 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 134 ) 135 136 return nil 137 }) 138 }) 139 }) 140 141 Context("When i18n4go4go is run with the -d -r flags", func() { 142 BeforeEach(func() { 143 inputFilesPath = filepath.Join(inputFilesPath, "..") 144 145 session := Runi18n("extract-strings", "-v", "--po", "--meta", "-d", inputFilesPath, "-o", outputPath, "-r", "--ignore-regexp", "^[.]\\w+.go$") 146 Ω(session.ExitCode()).Should(Equal(0)) 147 }) 148 149 It("Walks input directories and compares each group of generated output to expected output", func() { 150 filepath.Walk(inputFilesPath, func(path string, info os.FileInfo, err error) error { 151 if info.IsDir() { 152 return nil 153 } 154 155 CompareExpectedToGeneratedTraslationJson( 156 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 157 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.json"}, ".")), 158 ) 159 160 CompareExpectedToGeneratedPo( 161 filepath.Join(expectedFilesPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 162 filepath.Join(outputPath, strings.Join([]string{filepath.Base(path), "en.po"}, ".")), 163 ) 164 165 return nil 166 }) 167 }) 168 }) 169 170 }) 171 })