github.com/CharukaK/i18n4go@v0.6.0/integration/show_missing_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 show_missing_strings_test 16 17 import ( 18 "os" 19 "path/filepath" 20 21 . "github.com/CharukaK/i18n4go/integration/test_helpers" 22 . "github.com/onsi/ginkgo" 23 . "github.com/onsi/gomega" 24 . "github.com/onsi/gomega/gbytes" 25 . "github.com/onsi/gomega/gexec" 26 ) 27 28 var _ = Describe("show-missing-strings -d dirName", func() { 29 var ( 30 fixturesPath string 31 inputFilesPath string 32 session *Session 33 ) 34 35 BeforeEach(func() { 36 _, err := os.Getwd() 37 Ω(err).ShouldNot(HaveOccurred()) 38 39 fixturesPath = filepath.Join("..", "..", "test_fixtures", "show_missing_strings") 40 inputFilesPath = filepath.Join(fixturesPath, "d_option", "input_files") 41 }) 42 43 Context("Using legacy commands", func() { 44 45 Context("When all the translated strings are in the json resource", func() { 46 BeforeEach(func() { 47 languageFilePath := filepath.Join(inputFilesPath, "no_missing_strings", "app.go.en.json") 48 codeDirPath := filepath.Join(inputFilesPath, "no_missing_strings", "code") 49 session = Runi18n("-c", "show-missing-strings", "-d", codeDirPath, "--i18n-strings-filename", languageFilePath) 50 51 Eventually(session.ExitCode()).Should(Equal(0)) 52 }) 53 54 It("Should output nothing", func() { 55 Ω(session).Should(Say("")) 56 }) 57 }) 58 59 Context("When there are strings missing from the json resource", func() { 60 BeforeEach(func() { 61 languageFilePath := filepath.Join(inputFilesPath, "missing_strings", "app.go.en.json") 62 codeDirPath := filepath.Join(inputFilesPath, "missing_strings", "code") 63 session = Runi18n("-c", "show-missing-strings", "-d", codeDirPath, "--i18n-strings-filename", languageFilePath) 64 65 Eventually(session.ExitCode()).Should(Equal(1)) 66 }) 67 68 It("Should output something", func() { 69 Ω(session).Should(Say("Missing")) 70 }) 71 }) 72 73 Context("When there are extra strings in the resource file", func() { 74 BeforeEach(func() { 75 languageFilePath := filepath.Join(inputFilesPath, "extra_strings", "app.go.en.json") 76 codeDirPath := filepath.Join(inputFilesPath, "extra_strings", "code") 77 session = Runi18n("-c", "show-missing-strings", "-d", codeDirPath, "--i18n-strings-filename", languageFilePath) 78 79 Eventually(session.ExitCode()).Should(Equal(1)) 80 }) 81 82 It("Should output something", func() { 83 Ω(session).Should(Say("Additional")) 84 }) 85 }) 86 }) 87 88 Context("Using cobra commands", func() { 89 90 Context("When all the translated strings are in the json resource", func() { 91 BeforeEach(func() { 92 languageFilePath := filepath.Join(inputFilesPath, "no_missing_strings", "app.go.en.json") 93 codeDirPath := filepath.Join(inputFilesPath, "no_missing_strings", "code") 94 session = Runi18n("show-missing-strings", "-d", codeDirPath, "--i18n-strings-filename", languageFilePath) 95 96 Eventually(session.ExitCode()).Should(Equal(0)) 97 }) 98 99 It("Should output nothing", func() { 100 Ω(session).Should(Say("")) 101 }) 102 }) 103 104 Context("When there are strings missing from the json resource", func() { 105 BeforeEach(func() { 106 languageFilePath := filepath.Join(inputFilesPath, "missing_strings", "app.go.en.json") 107 codeDirPath := filepath.Join(inputFilesPath, "missing_strings", "code") 108 session = Runi18n("show-missing-strings", "-d", codeDirPath, "--i18n-strings-filename", languageFilePath) 109 110 Eventually(session.ExitCode()).Should(Equal(1)) 111 }) 112 113 It("Should output something", func() { 114 Ω(session).Should(Say("Missing")) 115 }) 116 }) 117 118 Context("When there are extra strings in the resource file", func() { 119 BeforeEach(func() { 120 languageFilePath := filepath.Join(inputFilesPath, "extra_strings", "app.go.en.json") 121 codeDirPath := filepath.Join(inputFilesPath, "extra_strings", "code") 122 session = Runi18n("show-missing-strings", "-d", codeDirPath, "--i18n-strings-filename", languageFilePath) 123 124 Eventually(session.ExitCode()).Should(Equal(1)) 125 }) 126 127 It("Should output something", func() { 128 Ω(session).Should(Say("Additional")) 129 }) 130 }) 131 }) 132 })