Skip to content

Commit

Permalink
e2e: add alloc_logs test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrasell committed Apr 3, 2023
1 parent 07b5a14 commit e325d0b
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
45 changes: 45 additions & 0 deletions e2e/alloc_logs/alloc_logs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package alloc_logs

import (
"testing"

"github.com/hashicorp/nomad/e2e/e2eutil"
"github.com/hashicorp/nomad/helper/uuid"
"github.com/shoenig/test/must"
)

func TestAllocLogs(t *testing.T) {

// Wait until we have a usable cluster before running the tests.
nomadClient := e2eutil.NomadClient(t)
e2eutil.WaitForLeader(t, nomadClient)
e2eutil.WaitForNodesReady(t, nomadClient, 1)

// Run our test cases.
t.Run("TestAllocLogs_MixedFollow", testMixedFollow)
}

func testMixedFollow(t *testing.T) {

nomadClient := e2eutil.NomadClient(t)

// Generate our job ID which will be used for the entire test.
jobID := "alloc-logs-mixed-follow-" + uuid.Short()
jobIDs := []string{jobID}

// Ensure jobs are cleaned.
t.Cleanup(e2eutil.CleanupJobsAndGC(t, &jobIDs))

allocStubs := e2eutil.RegisterAndWaitForAllocs(t, nomadClient, "./input/mixed-output.nomad", jobID, "")
must.Len(t, 1, allocStubs)

// Run the alloc logs command which we expect to capture both stdout and
// stderr logs. The command will reach its timeout and therefore return an
// error. We want to ignore this, as it's expected. Any other error is
// terminal.
out, err := e2eutil.Command("nomad", "alloc", "logs", "-f", allocStubs[0].ID)
if err != nil {
must.ErrorContains(t, err, "failed: signal: killed")
}
must.StrContains(t, out, "stdout\nstderr\nstdout\nstderr\nstdout\nstderr")
}
6 changes: 6 additions & 0 deletions e2e/alloc_logs/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Package alloc_logs provides end-to-end tests for Nomads allocation logging
// functionality.
//
// In order to run this test suite only, from the e2e directory you can trigger
// go test -v -run '^TestAllocLogs' ./alloc_logs
package alloc_logs
35 changes: 35 additions & 0 deletions e2e/alloc_logs/input/mixed-output.nomad
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
job "alloc-logs" {
datacenters = ["dc1"]
type = "service"

#constraint {
# attribute = "${attr.kernel.name}"
# value = "linux"
#}

group "alloc-logs" {

task "test" {
driver = "raw_exec"

template {
data = <<EOH
while true
do
echo stdout >&1
sleep 1
echo stderr >&2
sleep 1
done
EOH

destination = "local/echo.sh"
}

config {
command = "bash"
args = ["local/echo.sh"]
}
}
}
}

0 comments on commit e325d0b

Please sign in to comment.