-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes basic job success checks (#78)
* Adds support for new job status string * Fixes job status checking, and adds basic test
- Loading branch information
Showing
2 changed files
with
61 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package hope | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
import ( | ||
log "github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/suite" | ||
) | ||
|
||
import ( | ||
"github.com/Eagerod/hope/pkg/kubeutil" | ||
) | ||
|
||
// Implemented as a suite to allow manipulating kubeutil.kubectl funcs | ||
type KubectlJobsTestSuite struct { | ||
suite.Suite | ||
|
||
originalGetKubectl func(kubectl *kubeutil.Kubectl, args ...string) (string, error) | ||
} | ||
|
||
func (s *KubectlJobsTestSuite) SetupTest() { | ||
s.originalGetKubectl = kubeutil.GetKubectl | ||
|
||
} | ||
|
||
func (s *KubectlJobsTestSuite) TeardownTest() { | ||
kubeutil.GetKubectl = s.originalGetKubectl | ||
} | ||
|
||
// Actual test method to run the suite | ||
func TestKubectlJobs(t *testing.T) { | ||
suite.Run(t, new(KubectlJobsTestSuite)) | ||
} | ||
|
||
func (s *KubectlJobsTestSuite) TestGetJobStatus() { | ||
t := s.T() | ||
|
||
kubeutil.GetKubectl = func(kubectl *kubeutil.Kubectl, args ...string) (string, error) { | ||
return "SuccessCriteriaMet\nComplete", nil | ||
} | ||
|
||
kubectl := kubeutil.Kubectl{} | ||
status, err := GetJobStatus(log.WithFields(log.Fields{}), &kubectl, "default", "imaginary-job") | ||
assert.Nil(t, err) | ||
assert.Equal(t, status, JobStatusComplete) | ||
} |