Skip to content

Commit

Permalink
copy artifact outside
Browse files Browse the repository at this point in the history
Signed-off-by: Alessio Greggi <[email protected]>
  • Loading branch information
alegrey91 committed Sep 7, 2024
1 parent 572f907 commit d134284
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
3 changes: 3 additions & 0 deletions tests/apply_trace.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ exec_cmd fwdctl apply --file rules-wrong6.yaml
! fwd_exists lo tcp 3001 127.0.0.1 80
! fwd_exists lo tcp 3002 127.0.0.1 80

exec ls -lsa integration-test-syscalls/
cp_dir integration-test-syscalls/ /home/runner/work/fwdctl/fwdctl/integration-test-syscalls

-- rules.yml --
rules:
- dport: 3000
Expand Down
27 changes: 13 additions & 14 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,44 +93,42 @@ func execCmd(ts *testscript.TestScript, neg bool, args []string) {
ts.Fatalf("unexpected go command success")
}
}
if err := moveArtifacts("integration-test-syscalls", "/home/runner/work/fwdctl/fwdctl/integration-test-syscalls"); err != nil {
ts.Fatalf(err.Error())
}
}

func moveArtifacts(src, dst string) error {
func cpDir(ts *testscript.TestScript, neg bool, args []string) {
if len(args) != 2 {
ts.Fatalf("bad arguments number")
}
src := args[0]
dst := args[1]
entries, err := os.ReadDir(src)
if err != nil {
return err
ts.Fatalf("%v", err)
}

if err := os.MkdirAll(dst, 0755); err != nil {
return err
ts.Fatalf("%v", err)
}

for _, entry := range entries {
srcPath := filepath.Join(src, entry.Name())
dstPath := filepath.Join(dst, entry.Name())

recursionArgs := []string{src, dst}
if entry.IsDir() {
err = moveArtifacts(srcPath, dstPath)
if err != nil {
return err
}
cpDir(ts, neg, recursionArgs)
} else {
data, err := os.ReadFile(srcPath)
if err != nil {
return err
ts.Fatalf("%v", err)
}

err = os.WriteFile(dstPath, data, fs.ModeAppend)
if err != nil {
return err
ts.Fatalf("%v", err)
}
}
}

return nil
}

func execBackground(ts *testscript.TestScript, command string, args ...string) (*exec.Cmd, error) {
Expand Down Expand Up @@ -164,5 +162,6 @@ func customCommands() map[string]func(ts *testscript.TestScript, neg bool, args
// invoke as "fwd_exists iface proto dest_port src_addr src_port"
"fwd_exists": fwdExists,
"exec_cmd": execCmd,
"cp_dir": cpDir,
}
}

0 comments on commit d134284

Please sign in to comment.