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:
parent
d62c34b9f9
commit
9aa9779d80
|
@ -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 {
|
if job == nil {
|
||||||
return nil, nil, errors.New("must pass non-nil job")
|
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
|
// Setup the request
|
||||||
req := &JobPlanRequest{
|
req := &JobPlanRequest{
|
||||||
|
|
|
@ -2059,6 +2059,12 @@ func TestJobs_Plan(t *testing.T) {
|
||||||
_, _, err = jobs.Plan(nil, true, nil)
|
_, _, err = jobs.Plan(nil, true, nil)
|
||||||
must.Error(t, err)
|
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
|
// Make a plan request
|
||||||
planResp, wm, err := jobs.Plan(job, true, nil)
|
planResp, wm, err := jobs.Plan(job, true, nil)
|
||||||
must.NoError(t, err)
|
must.NoError(t, err)
|
||||||
|
|
Loading…
Reference in New Issue