Skip to content

Commit

Permalink
Merge pull request #3140 from hashicorp/f-round-trip-test
Browse files Browse the repository at this point in the history
Integration test for round tripping a job.
  • Loading branch information
dadgar authored Sep 5, 2017
2 parents 81bc534 + 0f1b5ba commit f585d9f
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion command/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package command_test
package command

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
"testing"

"github.com/hashicorp/nomad/api"
"github.com/stretchr/testify/assert"
)

func TestIntegration_Command_NomadInit(t *testing.T) {
Expand Down Expand Up @@ -32,3 +39,48 @@ func TestIntegration_Command_NomadInit(t *testing.T) {
}
}
}

func TestIntegration_Command_RoundTripJob(t *testing.T) {
assert := assert.New(t)
t.Parallel()
tmpDir, err := ioutil.TempDir("", "nomadtest-rootsecretdir")
assert.Nil(err)
defer os.RemoveAll(tmpDir)

// Start in dev mode so we get a node registration
srv, client, url := testServer(t, true, nil)
defer srv.Shutdown()

{
cmd := exec.Command("nomad", "init")
cmd.Dir = tmpDir
assert.Nil(cmd.Run())
}

{
cmd := exec.Command("nomad", "run", "example.nomad")
cmd.Dir = tmpDir
cmd.Env = []string{fmt.Sprintf("NOMAD_ADDR=%s", url)}
err := cmd.Run()
if err != nil && !strings.Contains(err.Error(), "exit status 2") {
t.Fatalf("error running example.nomad: %v", err)
}
}

{
cmd := exec.Command("nomad", "inspect", "example")
cmd.Dir = tmpDir
cmd.Env = []string{fmt.Sprintf("NOMAD_ADDR=%s", url)}
out, err := cmd.Output()
assert.Nil(err)

var req api.JobRegisterRequest
dec := json.NewDecoder(bytes.NewReader(out))
assert.Nil(dec.Decode(&req))

var resp api.JobRegisterResponse
_, err = client.Raw().Write("/v1/jobs", req, &resp, nil)
assert.Nil(err)
assert.NotZero(resp.EvalID)
}
}

0 comments on commit f585d9f

Please sign in to comment.