Skip to content

Commit

Permalink
tests: Fix lint problems on job.go
Browse files Browse the repository at this point in the history
Signed-off-by: Or Shoval <[email protected]>
  • Loading branch information
oshoval committed Jul 19, 2023
1 parent d8ddc45 commit 11fcc68
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions tests/libnet/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,17 @@ fi`,
// which tries to contact the host on the provided port.
// It expects to receive "Hello World!" to succeed.
func NewHelloWorldJobTCP(host string, port string) *batchv1.Job {
check := fmt.Sprintf(`set -x; x="$(head -n 1 < <(nc %s %s -i 3 -w 3 --no-shutdown))"; echo "$x" ; if [ "$x" = "Hello World!" ]; then echo "succeeded"; exit 0; else echo "failed"; exit 1; fi`, host, port)
check := fmt.Sprintf(`set -x; x="$(head -n 1 < <(nc %s %s -i 3 -w 3 --no-shutdown))"; echo "$x" ; \
if [ "$x" = "Hello World!" ]; then echo "succeeded"; exit 0; else echo "failed"; exit 1; fi`, host, port)
return NewHelloWorldJob(check)
}

// NewHelloWorldJobHTTP gets an IP address and a port, which it uses to create a pod.
// This pod tries to contact the host on the provided port, over HTTP.
// On success - it expects to receive "Hello World!".
func NewHelloWorldJobHTTP(host string, port string) *batchv1.Job {
check := fmt.Sprintf(`set -x; x="$(head -n 1 < <(curl --silent %s:%s))"; echo "$x" ; if [ "$x" = "Hello World!" ]; then echo "succeeded"; exit 0; else echo "failed"; exit 1; fi`, libnet.FormatIPForURL(host), port)
check := fmt.Sprintf(`set -x; x="$(head -n 1 < <(curl --silent %s:%s))"; echo "$x" ; \
if [ "$x" = "Hello World!" ]; then echo "succeeded"; exit 0; else echo "failed"; exit 1; fi`, libnet.FormatIPForURL(host), port)
return NewHelloWorldJob(check)
}

Expand All @@ -105,15 +107,15 @@ func WaitForJob(job *batchv1.Job, toSucceed bool, timeout time.Duration) error {

jobFailedError := func(job *batchv1.Job) error {
if toSucceed {
return fmt.Errorf("Job %s finished with failure, status: %+v", job.Name, job.Status)
return fmt.Errorf("job %s finished with failure, status: %+v", job.Name, job.Status)
}
return nil
}
jobCompleteError := func(job *batchv1.Job) error {
if toSucceed {
return nil
}
return fmt.Errorf("Job %s finished with success, status: %+v", job.Name, job.Status)
return fmt.Errorf("job %s finished with success, status: %+v", job.Name, job.Status)
}

const finish = true
Expand All @@ -133,13 +135,17 @@ func WaitForJob(job *batchv1.Job, toSucceed bool, timeout time.Duration) error {
if c.Status == k8sv1.ConditionTrue {
return finish, jobFailedError(job)
}
case batchv1.JobSuspended:
break
case batchv1.JobFailureTarget:
break
}
}
return !finish, nil
})

if err != nil {
return fmt.Errorf("Job %s timeout reached, status: %+v, err: %v", job.Name, job.Status, err)
return fmt.Errorf("job %s timeout reached, status: %+v, err: %v", job.Name, job.Status, err)
}
return nil
}
Expand Down

0 comments on commit 11fcc68

Please sign in to comment.