1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
nodot_command.go 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
package main
import (
"bufio"
"flag"
"github.com/onsi/ginkgo/ginkgo/nodot"
"io/ioutil"
"os"
"path/filepath"
"regexp"
)
func BuildNodotCommand() *Command {
return &Command{
Name: "nodot",
FlagSet: flag.NewFlagSet("bootstrap", flag.ExitOnError),
UsageCommand: "ginkgo nodot",
Usage: []string{
"Update the nodot declarations in your test suite",
"Any missing declarations (from, say, a recently added matcher) will be added to your bootstrap file.",
"If you've renamed a declaration, that name will be honored and not overwritten.",
},
Command: updateNodot,
}
}
func updateNodot(args []string, additionalArgs []string) {
suiteFile, perm := findSuiteFile()
data, err := ioutil.ReadFile(suiteFile)
if err != nil {
complainAndQuit("Failed to update nodot declarations: " + err.Error())
}
content, err := nodot.ApplyNoDot(data)
if err != nil {
complainAndQuit("Failed to update nodot declarations: " + err.Error())
}
ioutil.WriteFile(suiteFile, content, perm)
goFmt(suiteFile)
}
func findSuiteFile() (string, os.FileMode) {
workingDir, err := os.Getwd()
if err != nil {
complainAndQuit("Could not find suite file for nodot: " + err.Error())
}
files, err := ioutil.ReadDir(workingDir)
if err != nil {
complainAndQuit("Could not find suite file for nodot: " + err.Error())
}
re := regexp.MustCompile(`RunSpecs\(|RunSpecsWithDefaultAndCustomReporters\(|RunSpecsWithCustomReporters\(`)
for _, file := range files {
if file.IsDir() {
continue
}
path := filepath.Join(workingDir, file.Name())
f, err := os.Open(path)
if err != nil {
complainAndQuit("Could not find suite file for nodot: " + err.Error())
}
if re.MatchReader(bufio.NewReader(f)) {
return path, file.Mode()
}
}
complainAndQuit("Could not find a suite file for nodot: you need a bootstrap file that call's Ginkgo's RunSpecs() command.\nTry running ginkgo bootstrap first.")
return "", 0
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v1.0.1

搜索帮助

344bd9b3 5694891 D2dac590 5694891