diff --git a/pkg/hubtest/hubtest_item.go b/pkg/hubtest/hubtest_item.go index 475f42cf6..5313fc6cf 100644 --- a/pkg/hubtest/hubtest_item.go +++ b/pkg/hubtest/hubtest_item.go @@ -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() } diff --git a/pkg/hubtest/scenario_assert.go b/pkg/hubtest/scenario_assert.go index 2e2a4e9c8..92b00f640 100644 --- a/pkg/hubtest/scenario_assert.go +++ b/pkg/hubtest/scenario_assert.go @@ -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) diff --git a/pkg/hubtest/utils.go b/pkg/hubtest/utils.go index 73de3510b..0ace4860d 100644 --- a/pkg/hubtest/utils.go +++ b/pkg/hubtest/utils.go @@ -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