Skip to content

Commit 941c7d5

Browse files
committed
moving checks to their relevant stops so unit tests work
1 parent 77931fb commit 941c7d5

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

Diff for: cmd/extract/extract.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,29 @@ Usage: from the root minikube directory, go run cmd/extract/extract.go
2424
package main
2525

2626
import (
27+
"os"
28+
"strings"
29+
2730
"k8s.io/minikube/pkg/minikube/extract"
2831
)
2932

3033
func main() {
3134
paths := []string{"cmd", "pkg"}
3235
functions := []string{"translate.T"}
3336
outDir := "translations"
34-
err := extract.TranslatableStrings(paths, functions, outDir)
37+
cwd, err := os.Getwd()
38+
if err != nil {
39+
panic("Getting current working directory failed")
40+
}
41+
42+
if strings.Contains(cwd, "cmd") {
43+
panic("run extract.go from the minikube root directory")
44+
}
45+
46+
if _, err = os.Stat(extract.ErrMapFile); os.IsNotExist(err) {
47+
panic("err_map.go doesn't exist")
48+
}
49+
err = extract.TranslatableStrings(paths, functions, outDir)
3550

3651
if err != nil {
3752
panic(err)

Diff for: pkg/minikube/extract/extract.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var blacklist = []string{
4747
"opt %s",
4848
}
4949

50-
const errMapFile string = "pkg/minikube/problem/err_map.go"
50+
const ErrMapFile string = "pkg/minikube/problem/err_map.go"
5151

5252
// state is a struct that represent the current state of the extraction process
5353
type state struct {
@@ -114,19 +114,6 @@ func setParentFunc(e *state, f string) {
114114

115115
// TranslatableStrings finds all strings to that need to be translated in paths and prints them out to all json files in output
116116
func TranslatableStrings(paths []string, functions []string, output string) error {
117-
cwd, err := os.Getwd()
118-
if err != nil {
119-
return errors.Wrap(err, "Getting current working directory")
120-
}
121-
122-
if strings.Contains(cwd, "cmd") {
123-
return errors.New("run extract.go from the minikube root directory")
124-
}
125-
126-
if _, err = os.Stat(errMapFile); os.IsNotExist(err) {
127-
return errors.New("err_map.go doesn't exist")
128-
}
129-
130117
e, err := newExtractor(functions)
131118

132119
if err != nil {
@@ -178,7 +165,7 @@ func inspectFile(e *state) error {
178165
return err
179166
}
180167

181-
if e.filename == errMapFile {
168+
if e.filename == ErrMapFile {
182169
return extractAdvice(file, e)
183170
}
184171

0 commit comments

Comments
 (0)