mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
api: prevent panic on job plan (#17689)
Check for a nil job ID to prevent a panic when calling Jobs().Plan().
This commit is contained in:
3
.changelog/17689.txt
Normal file
3
.changelog/17689.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
```release-note:bug
|
||||
api: Fixed a bug that caused a panic when calling the `Jobs().Plan()` function with a job missing an ID
|
||||
```
|
||||
@@ -447,6 +447,9 @@ func (j *Jobs) PlanOpts(job *Job, opts *PlanOptions, q *WriteOptions) (*JobPlanR
|
||||
if job == nil {
|
||||
return nil, nil, errors.New("must pass non-nil job")
|
||||
}
|
||||
if job.ID == nil {
|
||||
return nil, nil, errors.New("job is missing ID")
|
||||
}
|
||||
|
||||
// Setup the request
|
||||
req := &JobPlanRequest{
|
||||
|
||||
@@ -2059,6 +2059,12 @@ func TestJobs_Plan(t *testing.T) {
|
||||
_, _, err = jobs.Plan(nil, true, nil)
|
||||
must.Error(t, err)
|
||||
|
||||
// Check that passing a nil job ID fails
|
||||
invalidJob := testJob()
|
||||
invalidJob.ID = nil
|
||||
_, _, err = jobs.Plan(invalidJob, true, nil)
|
||||
must.Error(t, err)
|
||||
|
||||
// Make a plan request
|
||||
planResp, wm, err := jobs.Plan(job, true, nil)
|
||||
must.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user