Merge pull request #14189 from hashicorp/f-update-nomad-provider-tests

provider/nomad: Update acceptance tests to correctly reflect nomad API
This commit is contained in:
Jake Champlin 2017-05-03 17:02:58 -04:00 committed by GitHub
commit 5152311338
1 changed files with 13 additions and 8 deletions

View File

@ -207,15 +207,17 @@ func testResourceJob_checkExists(s *terraform.State) error {
func testResourceJob_checkDestroy(jobID string) r.TestCheckFunc {
return func(*terraform.State) error {
client := testProvider.Meta().(*api.Client)
_, _, err := client.Jobs().Info(jobID, nil)
if err != nil && strings.Contains(err.Error(), "404") {
job, _, err := client.Jobs().Info(jobID, nil)
// This should likely never happen, due to how nomad caches jobs
if err != nil && strings.Contains(err.Error(), "404") || job == nil {
return nil
}
if err == nil {
err = errors.New("not destroyed")
if job.Status != "dead" {
return fmt.Errorf("Job %q has not been stopped. Status: %s", jobID, job.Status)
}
return err
return nil
}
}
@ -284,9 +286,12 @@ func testResourceJob_updateCheck(s *terraform.State) error {
{
// Verify foo doesn't exist
_, _, err := client.Jobs().Info("foo", nil)
if err == nil {
return errors.New("reading foo success")
job, _, err := client.Jobs().Info("foo", nil)
if err != nil {
return fmt.Errorf("error reading %q job: %s", "foo", err)
}
if job.Status != "dead" {
return fmt.Errorf("%q job is not dead. Status: %q", "foo", job.Status)
}
}