From c72613d226caa786c30119c1b023f4f4e4ae5850 Mon Sep 17 00:00:00 2001 From: Dominik Froehlich Date: Fri, 30 Jun 2023 13:50:01 +0200 Subject: [PATCH] f --- acceptance-tests/basic_pcap_test.go | 17 ++++++++--------- acceptance-tests/bosh_helpers.go | 4 ++-- acceptance-tests/remote.go | 11 +---------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/acceptance-tests/basic_pcap_test.go b/acceptance-tests/basic_pcap_test.go index 83e80ab3..b6394e80 100644 --- a/acceptance-tests/basic_pcap_test.go +++ b/acceptance-tests/basic_pcap_test.go @@ -31,21 +31,20 @@ var _ = Describe("Pcap Deployment", func() { pcapBoshCli := pcapBoshCliFile.Name() By("Downloading remote pcap-bosh-cli-linux-amd64 to " + pcapBoshCli) - err = downloadFile(info, "/var/vcap/packages/pcap-api/bin/cli/build/pcap-bosh-cli-linux-amd64", pcapBoshCli, 0755) + err = downloadFile(info, "/var/vcap/packages/pcap-api/bin/cli/build/pcap-bosh-cli-linux-amd64", pcapBoshCliFile, 0755) Expect(err).NotTo(HaveOccurred()) - - By("Starting capture of traffic on pcap-agent instance") - pcapFile, err := os.CreateTemp("", "test-*.pcap") + err = pcapBoshCliFile.Close() Expect(err).NotTo(HaveOccurred()) - _ = pcapFile.Close() + + pcapFile := fmt.Sprintf("%s-capture.pcap", pcapBoshCli) + By("Starting capture of traffic on pcap-agent instance to file " + pcapFile) cmdPcap := exec.Command( pcapBoshCli, "-d", deploymentNameForTestNode(), "-g", "pcap-agent", - "-o", pcapFile.Name(), + "-o", pcapFile, "-u", fmt.Sprintf("http://%s:8080/", info.PcapAPIPublicIP), - "-v", - "-F") + "-v") sessionPcap, err := gexec.Start(cmdPcap, GinkgoWriter, GinkgoWriter) Expect(err).NotTo(HaveOccurred()) @@ -61,7 +60,7 @@ var _ = Describe("Pcap Deployment", func() { Eventually(sessionPcap, time.Minute, time.Second).Should(gexec.Exit()) By("Checking that the capture has produced a valid pcap file") - pcapFileStat, err := pcapFile.Stat() + pcapFileStat, err := os.Stat(pcapFile) Expect(err).NotTo(HaveOccurred()) Expect(pcapFileStat.Size()).To(BeNumerically(">", 24)) // 24 bytes == pcap header only }) diff --git a/acceptance-tests/bosh_helpers.go b/acceptance-tests/bosh_helpers.go index e1a000a9..7a8eb148 100644 --- a/acceptance-tests/bosh_helpers.go +++ b/acceptance-tests/bosh_helpers.go @@ -348,6 +348,6 @@ func writeLog(s string) { } } -func downloadFile(info pcapInfo, remotePath, localPath string, permissions os.FileMode) error { - return copyFileFromRemote(info.SSHUser, info.PcapAPIPublicIP, info.SSHPrivateKey, remotePath, localPath, permissions) +func downloadFile(info pcapInfo, remotePath string, localFile *os.File, permissions os.FileMode) error { + return copyFileFromRemote(info.SSHUser, info.PcapAPIPublicIP, info.SSHPrivateKey, remotePath, localFile, permissions) } diff --git a/acceptance-tests/remote.go b/acceptance-tests/remote.go index 07bfb2a9..104fe4a4 100644 --- a/acceptance-tests/remote.go +++ b/acceptance-tests/remote.go @@ -49,7 +49,7 @@ func copyFileToRemote(user string, addr string, privateKey string, remotePath st return scpClient.CopyFile(context.Background(), fileReader, remotePath, permissions) } -func copyFileFromRemote(user string, addr string, privateKey string, remotePath string, localPath string, permissions os.FileMode) error { +func copyFileFromRemote(user string, addr string, privateKey string, remotePath string, localFile *os.File, permissions os.FileMode) error { clientConfig, err := buildSSHClientConfig(user, addr, privateKey) if err != nil { return err @@ -60,19 +60,10 @@ func copyFileFromRemote(user string, addr string, privateKey string, remotePath return err } - localFile, err := os.Create(localPath) - if err != nil { return err } - defer func() { - err = localFile.Close() - if err != nil { - writeLog(err.Error()) - } - }() - err = localFile.Chmod(permissions) if err != nil {