minor code review fixes to api/jobs

This commit is contained in:
Nick Ethier 2018-04-17 10:18:36 -04:00
parent f72c76c373
commit 1f99c3a0f7
No known key found for this signature in database
GPG Key ID: 07C1A3ECED90D24A
3 changed files with 12 additions and 12 deletions

View File

@ -38,11 +38,11 @@ type Jobs struct {
// JobsParseRequest is used for arguments of the /vi/jobs/parse endpoint // JobsParseRequest is used for arguments of the /vi/jobs/parse endpoint
type JobsParseRequest struct { type JobsParseRequest struct {
//JobHCL is an hcl jobspec // JobHCL is an hcl jobspec
JobHCL string JobHCL string
//Canonicalize is a flag as to if the server should return default values // Canonicalize is a flag as to if the server should return default values
//for unset fields // for unset fields
Canonicalize bool Canonicalize bool
} }
@ -53,7 +53,7 @@ func (c *Client) Jobs() *Jobs {
// Parse is used to convert the HCL repesentation of a Job to JSON server side. // Parse is used to convert the HCL repesentation of a Job to JSON server side.
// To parse the HCL client side see package github.com/hashicorp/nomad/jobspec // To parse the HCL client side see package github.com/hashicorp/nomad/jobspec
func (j *Jobs) Parse(jobHCL string, canonicalize bool) (*Job, error) { func (j *Jobs) ParseHCL(jobHCL string, canonicalize bool) (*Job, error) {
var job Job var job Job
req := &JobsParseRequest{ req := &JobsParseRequest{
JobHCL: jobHCL, JobHCL: jobHCL,

View File

@ -54,7 +54,7 @@ func TestJobs_Parse(t *testing.T) {
jobs := c.Jobs() jobs := c.Jobs()
checkJob := func(job *Job, expected string) { checkJob := func(job *Job, expectedRegion string) {
if job == nil { if job == nil {
t.Fatal("job should not be nil") t.Fatal("job should not be nil")
} }
@ -62,22 +62,22 @@ func TestJobs_Parse(t *testing.T) {
region := job.Region region := job.Region
if region == nil { if region == nil {
if expected != "" { if expectedRegion != "" {
t.Fatalf("expected job region to be '%s' but was unset", expected) t.Fatalf("expected job region to be '%s' but was unset", expectedRegion)
} }
} else { } else {
if expected != *region { if expectedRegion != *region {
t.Fatalf("expected job region '%s', but got '%s'", expected, *region) t.Fatalf("expected job region '%s', but got '%s'", expectedRegion, *region)
} }
} }
} }
job, err := jobs.Parse(mock.HCL(), true) job, err := jobs.ParseHCL(mock.HCL(), true)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
checkJob(job, "global") checkJob(job, "global")
job, err = jobs.Parse(mock.HCL(), false) job, err = jobs.ParseHCL(mock.HCL(), false)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }

View File

@ -233,7 +233,7 @@ $ curl \
## Parse Job ## Parse Job
This endpoint will parse an hcl jobspec and produce the equivalent json encoded This endpoint will parse a HCL jobspec and produce the equivalent JSON encoded
job. job.
| Method | Path | Produces | | Method | Path | Produces |