github.com/hernad/nomad@v1.6.112/e2e/example/example_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package example 5 6 import ( 7 "fmt" 8 "testing" 9 "time" 10 11 "github.com/hernad/nomad/e2e/v3/cluster3" 12 "github.com/hernad/nomad/e2e/v3/jobs3" 13 "github.com/hernad/nomad/e2e/v3/namespaces3" 14 "github.com/hernad/nomad/e2e/v3/util3" 15 "github.com/shoenig/test/must" 16 ) 17 18 func TestExample(t *testing.T) { 19 cluster3.Establish(t, 20 cluster3.Leader(), 21 cluster3.LinuxClients(1), 22 cluster3.Timeout(3*time.Second), 23 ) 24 25 t.Run("testSleep", testSleep) 26 t.Run("testNamespace", testNamespace) 27 t.Run("testEnv", testEnv) 28 } 29 30 func testSleep(t *testing.T) { 31 _, cleanup := jobs3.Submit(t, "./input/sleep.hcl") 32 t.Cleanup(cleanup) 33 } 34 35 func testNamespace(t *testing.T) { 36 name := util3.ShortID("example") 37 38 nsCleanup := namespaces3.Create(t, name) 39 t.Cleanup(nsCleanup) 40 41 _, jobCleanup := jobs3.Submit(t, "./input/sleep.hcl", jobs3.Namespace(name)) 42 t.Cleanup(jobCleanup) 43 } 44 45 func testEnv(t *testing.T) { 46 job, cleanup := jobs3.Submit(t, "./input/env.hcl", jobs3.WaitComplete("group")) 47 t.Cleanup(cleanup) 48 49 expect := fmt.Sprintf("NOMAD_JOB_ID=%s", job.JobID()) 50 logs := job.TaskLogs("group", "task") 51 must.StrContains(t, logs.Stdout, expect) 52 }