github.com/hernad/nomad@v1.6.112/e2e/alloc_logs/alloc_logs_test.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package alloc_logs
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/hernad/nomad/e2e/e2eutil"
    10  	"github.com/hernad/nomad/helper/uuid"
    11  	"github.com/shoenig/test/must"
    12  )
    13  
    14  func TestAllocLogs(t *testing.T) {
    15  
    16  	// Wait until we have a usable cluster before running the tests.
    17  	nomadClient := e2eutil.NomadClient(t)
    18  	e2eutil.WaitForLeader(t, nomadClient)
    19  	e2eutil.WaitForNodesReady(t, nomadClient, 1)
    20  
    21  	// Run our test cases.
    22  	t.Run("TestAllocLogs_MixedFollow", testMixedFollow)
    23  }
    24  
    25  func testMixedFollow(t *testing.T) {
    26  
    27  	nomadClient := e2eutil.NomadClient(t)
    28  
    29  	// Generate our job ID which will be used for the entire test.
    30  	jobID := "alloc-logs-mixed-follow-" + uuid.Short()
    31  	jobIDs := []string{jobID}
    32  
    33  	// Ensure jobs are cleaned.
    34  	t.Cleanup(e2eutil.CleanupJobsAndGC(t, &jobIDs))
    35  
    36  	allocStubs := e2eutil.RegisterAndWaitForAllocs(t, nomadClient, "./input/mixed-output.nomad", jobID, "")
    37  	must.Len(t, 1, allocStubs)
    38  
    39  	// Run the alloc logs command which we expect to capture both stdout and
    40  	// stderr logs. The command will reach its timeout and therefore return an
    41  	// error. We want to ignore this, as it's expected. Any other error is
    42  	// terminal.
    43  	out, err := e2eutil.Command("nomad", "alloc", "logs", "-f", allocStubs[0].ID)
    44  	if err != nil {
    45  		must.ErrorContains(t, err, "failed: signal: killed")
    46  	}
    47  	must.StrContains(t, out, "stdout\nstderr")
    48  }