Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acceptance-tests #29

Merged
merged 24 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c33cd97
ci: Setup for acceptance tests
b1tamara Jun 2, 2023
9f1ef93
ci: basic test
domdom82 Jun 15, 2023
524a05d
fix(pcap-bosh-cli): Assume https for BOSH URL on missing scheme.
domdom82 Jun 26, 2023
eb599c5
fix(pcap-bosh-cli): Use BOSH default port if none provided in config.
domdom82 Jun 26, 2023
96c59e6
fix(pcap-bosh-cli): abort if director does not have UAA
domdom82 Jun 27, 2023
f028559
fix(pcap-bosh-cli): missing env expansion on config write
domdom82 Jun 27, 2023
f369238
fix(pcap-bosh-cli): throw error if user not logged in.
domdom82 Jun 28, 2023
79a318c
ci: do interactive bosh login to get refresh token
domdom82 Jun 28, 2023
b85c455
fix(pcap-bosh-cli): remove unused type option. only valid for cf.
domdom82 Jun 28, 2023
968893e
fix(pcap-bosh-cli): missing null check
domdom82 Jun 28, 2023
06924c4
ci: use apache as capture target
domdom82 Jun 30, 2023
8c3439a
ci: update pipeline.yml with acceptance tests
domdom82 Jun 30, 2023
55b5873
Merge branch 'main' into acceptance-tests
domdom82 Jun 30, 2023
346c4ec
fix(packaging): libpcap.tgz -> libpcap.tar.gz
domdom82 Jul 3, 2023
404f2f3
ci: remove dev pipeline
domdom82 Jul 3, 2023
70e49ab
Apply suggestions from code review
domdom82 Jul 3, 2023
a1d74c0
refactor(acceptance tests): Add comments on review
domdom82 Jul 3, 2023
a91ee73
refactor(pcap-bosh-cli): remove obsolete else case
domdom82 Jul 3, 2023
41d9da9
doc(acceptance tests): add go docs to common functions.
domdom82 Jul 3, 2023
af01bf2
refactor(acceptance tests): remove unused client auth on pcap-agent c…
domdom82 Jul 3, 2023
b6689a3
doc(acceptance tests): Add README.me to acceptance tests and explain …
domdom82 Jul 3, 2023
8db65c0
fix(pcap-bosh-cli): fix linter errors
domdom82 Jul 4, 2023
d5b50b6
ci: update dependabot and linter checks to apply to acceptance-tests dir
b1tamara Jul 5, 2023
5ad9c1a
doc(ci): Add docs for local stemcell
domdom82 Jul 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions acceptance-tests/acceptance_tests_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package acceptance_tests

import (
"encoding/json"
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"testing"
)

func TestAcceptanceTests(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "AcceptanceTests Suite")
}

var _ = SynchronizedBeforeSuite(func() []byte {
// Load config once, and pass to other
// threads as JSON-encoded byte array
var err error
config, err = loadConfig()
Expect(err).NotTo(HaveOccurred())
domdom82 marked this conversation as resolved.
Show resolved Hide resolved

// Deploy pcap-api deployment
deployPcap(
baseManifestVars{
deploymentName: deploymentNameForTestNode(),
},
[]string{},
map[string]interface{}{},
true,
)

configBytes, err := json.Marshal(&config)
Expect(err).NotTo(HaveOccurred())

return configBytes
}, func(configBytes []byte) {
// populate thread-local variable `config` in each thread
err := json.Unmarshal(configBytes, &config)
Expect(err).NotTo(HaveOccurred())
})

var _ = SynchronizedAfterSuite(func() {
// Clean up deployments on each thread
deleteDeployment(deploymentNameForTestNode())
}, func() {})

func deploymentNameForTestNode() string {
return fmt.Sprintf("pcap-%d", GinkgoParallelProcess())
}
68 changes: 68 additions & 0 deletions acceptance-tests/basic_pcap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package acceptance_tests

import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
"net/http"
"os"
"os/exec"
"time"
)

var _ = Describe("Pcap Deployment", func() {
It("Deploys successfully", func() {
domdom82 marked this conversation as resolved.
Show resolved Hide resolved

info, _ := deployPcap(
baseManifestVars{
deploymentName: deploymentNameForTestNode(),
},
[]string{},
map[string]interface{}{},
true,
)

domdom82 marked this conversation as resolved.
Show resolved Hide resolved
By("Logging on to BOSH director to get a refresh token")
login(config.BoshClient, config.BoshClientSecret)

pcapBoshCliFile, err := os.CreateTemp("", "pcap-bosh-cli-*")
Expect(err).NotTo(HaveOccurred())
pcapBoshCli := pcapBoshCliFile.Name()

By("Downloading remote pcap-bosh-cli-linux-amd64 to " + pcapBoshCli)
domdom82 marked this conversation as resolved.
Show resolved Hide resolved
err = downloadFile(info, "/var/vcap/packages/pcap-api/bin/cli/build/pcap-bosh-cli-linux-amd64", pcapBoshCliFile, 0755)
Expect(err).NotTo(HaveOccurred())
err = pcapBoshCliFile.Close()
Expect(err).NotTo(HaveOccurred())

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,
"-u", fmt.Sprintf("http://%s:8080/", info.PcapAPIPublicIP),
domdom82 marked this conversation as resolved.
Show resolved Hide resolved
"-v")
sessionPcap, err := gexec.Start(cmdPcap, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())

By("Curling apache on pcap-agent instance to produce some traffic")
domdom82 marked this conversation as resolved.
Show resolved Hide resolved
for request := 1; request <= 10; request++ {
time.Sleep(time.Second)
response, err := http.Get(fmt.Sprintf("http://%s:80/", info.PcapAgentPublicIP))
Expect(err).NotTo(HaveOccurred())
Expect(response.StatusCode).To(Equal(200))
}

By("Stopping capture after curl has finished")
sessionPcap.Interrupt()
Eventually(sessionPcap, time.Minute, time.Second).Should(gexec.Exit())

By("Checking that the capture has produced a valid pcap file")
pcapFileStat, err := os.Stat(pcapFile)
Expect(err).NotTo(HaveOccurred())
Expect(pcapFileStat.Size()).To(BeNumerically(">", 24)) // 24 bytes == pcap header only
domdom82 marked this conversation as resolved.
Show resolved Hide resolved
})
})
Loading