Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sargun committed Jun 21, 2018
1 parent c0779f2 commit f5341f5
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
19 changes: 19 additions & 0 deletions executor/mock/jobrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ func (jobRunResponse *JobRunResponse) WaitForSuccess() bool {
return status == "TASK_FINISHED"
}

// WaitForFailure blocks on the jobs completion and returns true
// if it exits with a non-zero (user) error
func (jobRunResponse *JobRunResponse) WaitForFailure() bool {
status, err := jobRunResponse.WaitForCompletion()
if err != nil {
return false
}
return status == "TASK_FAILED"
}

// WaitForCompletion blocks on the jobs completion and returns its status
// if it completed successfully.
func (jobRunResponse *JobRunResponse) WaitForCompletion() (string, error) {
Expand Down Expand Up @@ -239,6 +249,15 @@ func RunJobExpectingSuccess(jobInput *JobInput) bool {
return jobResult.WaitForSuccess()
}

// RunJobExpectingFailure is similar to RunJob but returns true when the task completes successfully.
func RunJobExpectingFailure(jobInput *JobInput) bool {
jobRunner := NewJobRunner()
defer jobRunner.StopExecutor()

jobResult := jobRunner.StartJob(jobInput)
return jobResult.WaitForFailure()
}

// RunJob runs a single Titus task based on provided JobInput
func RunJob(jobInput *JobInput) (string, error) {
jobRunner := NewJobRunner()
Expand Down
56 changes: 56 additions & 0 deletions executor/mock/standalone/standalone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ var (
name: "titusoss/pty",
tag: "20180507-1525733149",
}
envLabel = testImage{
name: "titusoss/ubuntu-env-label",
tag: "20180621-1529540359",
}
)

// This file still uses log as opposed to using the testing library's built-in logging framework.
Expand Down Expand Up @@ -99,6 +103,10 @@ func TestStandalone(t *testing.T) {
testSchedBatch,
testSchedNormal,
testSchedIdle,
testNewEnvironmentLocationPositive,
testNewEnvironmentLocationNegative,
testOldEnvironmentLocationPositive,
testOldEnvironmentLocationNegative,
}
for _, fun := range testFunctions {
fullName := runtime.FuncForPC(reflect.ValueOf(fun).Pointer()).Name()
Expand Down Expand Up @@ -615,3 +623,51 @@ func testSchedIdle(t *testing.T, jobID string) {
t.Fail()
}
}

func testNewEnvironmentLocationPositive(t *testing.T, jobID string) {
ji := &mock.JobInput{
ImageName: envLabel.name,
Version: envLabel.tag,
Entrypoint: `cat /etc/nflx/base-environment.d/titus`,
JobID: jobID,
}
if !mock.RunJobExpectingSuccess(ji) {
t.Fail()
}
}

func testNewEnvironmentLocationNegative(t *testing.T, jobID string) {
ji := &mock.JobInput{
ImageName: envLabel.name,
Version: envLabel.tag,
Entrypoint: `cat /etc/profile.d/netflix_environment.sh`,
JobID: jobID,
}
if !mock.RunJobExpectingFailure(ji) {
t.Fail()
}
}

func testOldEnvironmentLocationPositive(t *testing.T, jobID string) {
ji := &mock.JobInput{
ImageName: ubuntu.name,
Version: ubuntu.tag,
Entrypoint: `cat /etc/profile.d/netflix_environment.sh`,
JobID: jobID,
}
if !mock.RunJobExpectingSuccess(ji) {
t.Fail()
}
}
func testOldEnvironmentLocationNegative(t *testing.T, jobID string) {

ji := &mock.JobInput{
ImageName: ubuntu.name,
Version: ubuntu.tag,
Entrypoint: `cat /etc/nflx/base-environment.d/titus`,
JobID: jobID,
}
if !mock.RunJobExpectingFailure(ji) {
t.Fail()
}
}

0 comments on commit f5341f5

Please sign in to comment.