Files
nomad/command/integration_test.go
Seth Hoenig 4d83733909 tests: swap testify for test in more places (#20028)
* tests: swap testify for test in plugins/csi/client_test.go

* tests: swap testify for test in testutil/

* tests: swap testify for test in host_test.go

* tests: swap testify for test in plugin_test.go

* tests: swap testify for test in utils_test.go

* tests: swap testify for test in scheduler/

* tests: swap testify for test in parse_test.go

* tests: swap testify for test in attribute_test.go

* tests: swap testify for test in plugins/drivers/

* tests: swap testify for test in command/

* tests: fixup some test usages

* go: run go mod tidy

* windows: cpuset test only on linux
2024-02-29 12:11:35 -06:00

93 lines
2.1 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package command
import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"strings"
"testing"
"github.com/hashicorp/nomad/api"
"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/client/testutil"
"github.com/shoenig/test/must"
)
func TestIntegration_Command_NomadInit(t *testing.T) {
ci.Parallel(t)
tmpDir := t.TempDir()
{
cmd := exec.Command("nomad", "job", "init")
cmd.Dir = tmpDir
if err := cmd.Run(); err != nil {
t.Fatalf("error running init: %v", err)
}
}
{
cmd := exec.Command("nomad", "job", "validate", "example.nomad.hcl")
cmd.Dir = tmpDir
cmd.Env = []string{`NOMAD_ADDR=http://127.0.0.1:0`}
if err := cmd.Run(); err != nil {
t.Fatalf("error validating example.nomad.hcl: %v", err)
}
}
}
func TestIntegration_Command_RoundTripJob(t *testing.T) {
ci.Parallel(t)
testutil.DockerCompatible(t)
tmpDir := t.TempDir()
// Start in dev mode so we get a node registration
srv, client, url := testServer(t, true, nil)
defer srv.Shutdown()
{
cmd := exec.Command("nomad", "job", "init", "-short")
cmd.Dir = tmpDir
must.NoError(t, cmd.Run())
}
{
cmd := exec.Command("nomad", "job", "run", "example.nomad.hcl")
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.hcl: %v", err)
}
}
{
cmd := exec.Command("nomad", "job", "inspect", "example")
cmd.Dir = tmpDir
cmd.Env = []string{fmt.Sprintf("NOMAD_ADDR=%s", url)}
out, err := cmd.Output()
must.NoError(t, err)
var req api.JobRegisterRequest
dec := json.NewDecoder(bytes.NewReader(out))
must.NoError(t, dec.Decode(&req))
var resp api.JobRegisterResponse
_, err = client.Raw().Write("/v1/jobs", req, &resp, nil)
must.NoError(t, err)
must.NotEq(t, "", resp.EvalID)
}
{
cmd := exec.Command("nomad", "job", "stop", "example")
cmd.Dir = tmpDir
cmd.Env = []string{fmt.Sprintf("NOMAD_ADDR=%s", url)}
_, err := cmd.Output()
must.NoError(t, err)
}
}