moving checks to their relevant stops so unit tests work

pull/4724/head
Sharif Elgamal 2019-07-15 13:38:12 -07:00
parent 77931fb4e2
commit 941c7d5fb2
No known key found for this signature in database
GPG Key ID: 23CC0225BD9FD702
2 changed files with 18 additions and 16 deletions

View File

@ -24,6 +24,9 @@ Usage: from the root minikube directory, go run cmd/extract/extract.go
package main
import (
"os"
"strings"
"k8s.io/minikube/pkg/minikube/extract"
)
@ -31,7 +34,19 @@ func main() {
paths := []string{"cmd", "pkg"}
functions := []string{"translate.T"}
outDir := "translations"
err := extract.TranslatableStrings(paths, functions, outDir)
cwd, err := os.Getwd()
if err != nil {
panic("Getting current working directory failed")
}
if strings.Contains(cwd, "cmd") {
panic("run extract.go from the minikube root directory")
}
if _, err = os.Stat(extract.ErrMapFile); os.IsNotExist(err) {
panic("err_map.go doesn't exist")
}
err = extract.TranslatableStrings(paths, functions, outDir)
if err != nil {
panic(err)

View File

@ -47,7 +47,7 @@ var blacklist = []string{
"opt %s",
}
const errMapFile string = "pkg/minikube/problem/err_map.go"
const ErrMapFile string = "pkg/minikube/problem/err_map.go"
// state is a struct that represent the current state of the extraction process
type state struct {
@ -114,19 +114,6 @@ func setParentFunc(e *state, f string) {
// TranslatableStrings finds all strings to that need to be translated in paths and prints them out to all json files in output
func TranslatableStrings(paths []string, functions []string, output string) error {
cwd, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "Getting current working directory")
}
if strings.Contains(cwd, "cmd") {
return errors.New("run extract.go from the minikube root directory")
}
if _, err = os.Stat(errMapFile); os.IsNotExist(err) {
return errors.New("err_map.go doesn't exist")
}
e, err := newExtractor(functions)
if err != nil {
@ -178,7 +165,7 @@ func inspectFile(e *state) error {
return err
}
if e.filename == errMapFile {
if e.filename == ErrMapFile {
return extractAdvice(file, e)
}