Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Use proper tmp dir in all persist output unit tests
Browse files Browse the repository at this point in the history
Tests were still flaky.

`ginkgo -p -r --randomizeAllSpecs -race -untilItFails pkg/kube/controllers/quarksjob`
  • Loading branch information
Mario Manno committed Feb 6, 2020
1 parent 1083a0b commit 6363929
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions pkg/kube/controllers/quarksjob/output_persistor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var _ = Describe("OutputPersistor", func() {
clientSet *clientfake.Clientset
versionedClientSet *clientsetfake.Clientset
po *quarksjob.OutputPersistor
tmpDir string
)

BeforeEach(func() {
Expand All @@ -40,7 +41,13 @@ var _ = Describe("OutputPersistor", func() {
clientSet = clientfake.NewSimpleClientset()
versionedClientSet = clientsetfake.NewSimpleClientset()
_, log := helper.NewTestLogger()
po = quarksjob.NewOutputPersistor(log, namespace, pod.Name, clientSet, versionedClientSet, "/tmp/")

var err error
tmpDir, err = ioutil.TempDir("/tmp", "quarks-job-unit")
Expect(err).ToNot(HaveOccurred())
Expect(os.Mkdir(filepath.Join(tmpDir, "busybox"), 0755)).ToNot(HaveOccurred())

po = quarksjob.NewOutputPersistor(log, namespace, pod.Name, clientSet, versionedClientSet, tmpDir)
})

JustBeforeEach(func() {
Expand All @@ -54,9 +61,7 @@ var _ = Describe("OutputPersistor", func() {
Context("when persisting one output", func() {
JustBeforeEach(func() {
// Create output file
err := os.MkdirAll("/tmp/busybox", os.ModePerm)
Expect(err).NotTo(HaveOccurred())
err = ioutil.WriteFile("/tmp/busybox/output.json", dataJSON, 0755)
err := ioutil.WriteFile(filepath.Join(tmpDir, "busybox", "output.json"), dataJSON, 0755)
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -179,15 +184,11 @@ var _ = Describe("OutputPersistor", func() {

Context("when persisting multiple outputs", func() {
JustBeforeEach(func() {
// Create output files
err := os.MkdirAll("/tmp/busybox", os.ModePerm)
Expect(err).NotTo(HaveOccurred())

err = ioutil.WriteFile("/tmp/busybox/output.json", dataJSON, 0755)
err := ioutil.WriteFile(filepath.Join(tmpDir, "busybox", "output.json"), dataJSON, 0755)
Expect(err).NotTo(HaveOccurred())
err = ioutil.WriteFile("/tmp/busybox/output-nats.json", dataJSON, 0755)
err = ioutil.WriteFile(filepath.Join(tmpDir, "busybox", "output-nats.json"), dataJSON, 0755)
Expect(err).NotTo(HaveOccurred())
err = ioutil.WriteFile("/tmp/busybox/output-nuts.json", dataJSON, 0755)
err = ioutil.WriteFile(filepath.Join(tmpDir, "busybox", "output-nuts.json"), dataJSON, 0755)
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -240,8 +241,6 @@ var _ = Describe("OutputPersistor", func() {
})

Context("when output persistence with fan out is configured", func() {
var tmpDir string

provideContent := func(data map[string]map[string]string) []byte {
tmp := map[string]string{}
for k, v := range data {
Expand All @@ -258,15 +257,6 @@ var _ = Describe("OutputPersistor", func() {
}

BeforeEach(func() {
var err error

tmpDir, err = ioutil.TempDir("/tmp", "testcase")
Expect(err).ToNot(HaveOccurred())
Expect(os.Mkdir(filepath.Join(tmpDir, "busybox"), 0755)).ToNot(HaveOccurred())

_, log := helper.NewTestLogger()
po = quarksjob.NewOutputPersistor(log, namespace, pod.Name, clientSet, versionedClientSet, tmpDir)

qJob.Spec.Output = &qjv1a1.Output{
OutputMap: qjv1a1.OutputMap{
"busybox": qjv1a1.NewFileToSecrets("provides.json", "link-nats-deployment", false),
Expand Down

0 comments on commit 6363929

Please sign in to comment.