Skip to content

Commit

Permalink
parseJobCommands: suport empty command slice
Browse files Browse the repository at this point in the history
  • Loading branch information
wpjunior committed Oct 11, 2023
1 parent 5b5f8cc commit 61bc293
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tsuru/client/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (c *JobCreate) Flags() *gnuflag.FlagSet {
}

func parseJobCommands(commands []string) ([]string, error) {
if len(commands) > 1 {
if len(commands) != 1 {
return commands, nil
}
quotedCommands := commands[0]
Expand Down
39 changes: 39 additions & 0 deletions tsuru/client/jobs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,45 @@ func (s *S) TestJobCreate(c *check.C) {
c.Assert(stdout.String(), check.Equals, expected)
}

func (s *S) TestJobCreateWithEmptyCommand(c *check.C) {
var stdout, stderr bytes.Buffer
context := cmd.Context{
Args: []string{"job-using-entrypoint", "ubuntu:latest"},
Stdout: &stdout,
Stderr: &stderr,
}
expected := "Job created\nUse \"tsuru job info job-using-entrypoint\" to check the status of the job\n"
trans := cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: `{"jobName":"job-using-entrypoint","status":"success"}`, Status: http.StatusCreated},
CondFunc: func(r *http.Request) bool {
c.Assert(r.URL.Path, check.Equals, "/1.13/jobs")
c.Assert(r.Method, check.Equals, "POST")
c.Assert(r.Header.Get("Content-Type"), check.Equals, "application/json")
data, err := io.ReadAll(r.Body)
c.Assert(err, check.IsNil)
var rr tsuru.InputJob
err = json.Unmarshal(data, &rr)
c.Assert(err, check.IsNil)
c.Assert(rr, check.DeepEquals, tsuru.InputJob{
Name: "job-using-entrypoint",
Pool: "somepool",
TeamOwner: "admin",
Container: tsuru.InputJobContainer{
Image: "ubuntu:latest",
},
Schedule: "* * * * *",
})
return true
},
}
client := cmd.NewClient(&http.Client{Transport: &trans}, nil, manager)
command := JobCreate{}
command.Flags().Parse(true, []string{"-t", "admin", "-o", "somepool", "-s", "* * * * *"})
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, expected)
}

func (s *S) TestJobCreateManual(c *check.C) {
var stdout, stderr bytes.Buffer
context := cmd.Context{
Expand Down

0 comments on commit 61bc293

Please sign in to comment.