refact: simplify hubtest CopyDir() (#2509)
This commit is contained in:
parent
7a4796d655
commit
6dadfcb2ef
3 changed files with 14 additions and 30 deletions
|
@ -97,7 +97,7 @@ func NewTest(name string, hubTest *HubTest) (*HubTestItem, error) {
|
|||
}
|
||||
err = yaml.Unmarshal(yamlFile, configFileData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Unmarshal: %v", err)
|
||||
return nil, fmt.Errorf("unmarshal: %v", err)
|
||||
}
|
||||
|
||||
parserAssertFilePath := filepath.Join(testPath, ParserAssertFileName)
|
||||
|
@ -516,7 +516,7 @@ func (t *HubTestItem) Run() error {
|
|||
return fmt.Errorf("unable to stat log file '%s': %s", logFile, err)
|
||||
}
|
||||
if logFileStat.Size() == 0 {
|
||||
return fmt.Errorf("Log file '%s' is empty, please fill it with log", logFile)
|
||||
return fmt.Errorf("log file '%s' is empty, please fill it with log", logFile)
|
||||
}
|
||||
|
||||
cmdArgs := []string{"-c", t.RuntimeConfigFilePath, "machines", "add", "testMachine", "--auto"}
|
||||
|
@ -555,7 +555,7 @@ func (t *HubTestItem) Run() error {
|
|||
if os.IsNotExist(err) {
|
||||
parserAssertFile, err := os.Create(t.ParserAssert.File)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
parserAssertFile.Close()
|
||||
}
|
||||
|
@ -591,7 +591,7 @@ func (t *HubTestItem) Run() error {
|
|||
if os.IsNotExist(err) {
|
||||
scenarioAssertFile, err := os.Create(t.ScenarioAssert.File)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
scenarioAssertFile.Close()
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ func (s *ScenarioAssert) AutoGenFromFile(filename string) (string, error) {
|
|||
}
|
||||
|
||||
func (s *ScenarioAssert) LoadTest(filename string, bucketpour string) error {
|
||||
var err error
|
||||
bucketDump, err := LoadScenarioDump(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("loading scenario dump file '%s': %+v", filename, err)
|
||||
|
|
|
@ -6,16 +6,17 @@ import (
|
|||
"path/filepath"
|
||||
)
|
||||
|
||||
func Copy(sourceFile string, destinationFile string) error {
|
||||
input, err := os.ReadFile(sourceFile)
|
||||
func Copy(src string, dst string) error {
|
||||
content, err := os.ReadFile(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.WriteFile(destinationFile, input, 0644)
|
||||
err = os.WriteFile(dst, content, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -60,6 +61,7 @@ func CopyDir(src string, dest string) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !file.IsDir() {
|
||||
return fmt.Errorf("Source " + file.Name() + " is not a directory!")
|
||||
}
|
||||
|
@ -75,32 +77,15 @@ func CopyDir(src string, dest string) error {
|
|||
}
|
||||
|
||||
for _, f := range files {
|
||||
|
||||
if f.IsDir() {
|
||||
|
||||
err = CopyDir(src+"/"+f.Name(), dest+"/"+f.Name())
|
||||
if err != nil {
|
||||
if err = CopyDir(filepath.Join(src, f.Name()), filepath.Join(dest, f.Name())); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err = Copy(filepath.Join(src, f.Name()), filepath.Join(dest, f.Name())); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if !f.IsDir() {
|
||||
|
||||
content, err := os.ReadFile(src + "/" + f.Name())
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
err = os.WriteFile(dest+"/"+f.Name(), content, 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
Loading…
Add table
Reference in a new issue