Skip to content

Commit

Permalink
add show run command to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
whatsadebugger committed Oct 20, 2018
1 parent 168bbe5 commit c06e107
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/remote_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ func (cli *Client) CreateServiceAgreement(c *clipkg.Context) error {
return cli.renderResponse(resp, &sa)
}

// ShowJobRun returns the status of the given Jobrun.
func (cli *Client) ShowJobRun(c *clipkg.Context) error {
if !c.Args().Present() {
return cli.errorOut(errors.New("Must pass the RunID to show"))
}
resp, err := cli.HTTP.Get("/v2/runs/" + c.Args().First())
if err != nil {
return cli.errorOut(err)
}
defer resp.Body.Close()
var job presenters.JobRun
return cli.renderAPIResponse(resp, &job)
}

// ShowJobSpec returns the status of the given JobID.
func (cli *Client) ShowJobSpec(c *clipkg.Context) error {
if !c.Args().Present() {
Expand Down
34 changes: 34 additions & 0 deletions cmd/remote_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,40 @@ func TestClient_GetJobSpecs(t *testing.T) {
assert.Equal(t, j1.ID, jobs[0].ID)
}

func TestClient_ShowJobRun_Exists(t *testing.T) {
t.Parallel()
app, cleanup := cltest.NewApplication()
defer cleanup()

j, _ := cltest.NewJobWithWebInitiator()
assert.NoError(t, app.Store.SaveJob(&j))

jr := cltest.CreateJobRunViaWeb(t, app, j, `{"value":"100"}`)

client, r := app.NewClientAndRenderer()

set := flag.NewFlagSet("test", 0)
set.Parse([]string{jr.ID})
c := cli.NewContext(nil, set, nil)
assert.NoError(t, client.ShowJobRun(c))
assert.Equal(t, 1, len(r.Renders))
assert.Equal(t, jr.ID, r.Renders[0].(*presenters.JobRun).ID)
}

func TestClient_ShowJobRun_NotFound(t *testing.T) {
t.Parallel()
app, cleanup := cltest.NewApplication()
defer cleanup()

client, r := app.NewClientAndRenderer()

set := flag.NewFlagSet("test", 0)
set.Parse([]string{"bogus-ID"})
c := cli.NewContext(nil, set, nil)
assert.Error(t, client.ShowJobRun(c))
assert.Empty(t, r.Renders)
}

func TestClient_ShowJobSpec_Exists(t *testing.T) {
app, cleanup := cltest.NewApplication()
defer cleanup()
Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ func Run(client *cmd.Client, args ...string) {
Usage: "Begin job run for specid",
Action: client.CreateJobRun,
},
{
Name: "showrun",
Aliases: []string{"sr"},
Usage: "Show a job run for a RunID",
Action: client.ShowJobRun,
},
{
Name: "backup",
Usage: "Backup the database of the running node",
Expand Down
1 change: 1 addition & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func ExampleRun() {
// show, s Show a specific job
// create, c Create job spec from JSON
// run, r Begin job run for specid
// showrun, sr Show a job run for a RunID
// backup Backup the database of the running node
// import, i Import a key file to use with the node
// bridge Add a new bridge to the node
Expand Down

0 comments on commit c06e107

Please sign in to comment.