Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
domdom82 committed Jun 30, 2023
1 parent 709031b commit c72613d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
17 changes: 8 additions & 9 deletions acceptance-tests/basic_pcap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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
})
Expand Down
4 changes: 2 additions & 2 deletions acceptance-tests/bosh_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
11 changes: 1 addition & 10 deletions acceptance-tests/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit c72613d

Please sign in to comment.