github.com/hernad/nomad@v1.6.112/e2e/connect/connect.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package connect 5 6 import ( 7 "os" 8 9 "github.com/hernad/nomad/e2e/e2eutil" 10 "github.com/hernad/nomad/e2e/framework" 11 "github.com/hernad/nomad/helper/uuid" 12 ) 13 14 const ( 15 // envConsulToken is the consul http token environment variable 16 envConsulToken = "CONSUL_HTTP_TOKEN" 17 18 // demoConnectJob is the example connect enabled job useful for testing 19 demoConnectJob = "connect/input/demo.nomad" 20 21 // demoConnectCustomProxyExposed is a connect job with custom sidecar_task 22 // that also uses the expose check feature. 23 demoConnectCustomProxyExposed = "connect/input/expose-custom.nomad" 24 25 // demoConnectNativeJob is the example connect native enabled job useful for testing 26 demoConnectNativeJob = "connect/input/native-demo.nomad" 27 28 // demoConnectIngressGateway is the example ingress gateway job useful for testing 29 demoConnectIngressGateway = "connect/input/ingress-gateway.nomad" 30 31 // demoConnectMultiIngressGateway is the example multi ingress gateway job useful for testing 32 demoConnectMultiIngressGateway = "connect/input/multi-ingress.nomad" 33 34 // demoConnectTerminatingGateway is the example terminating gateway job useful for testing 35 demoConnectTerminatingGateway = "connect/input/terminating-gateway.nomad" 36 ) 37 38 type ConnectE2ETest struct { 39 framework.TC 40 jobIds []string 41 } 42 43 func init() { 44 // Connect tests without Consul ACLs enabled. 45 framework.AddSuites(&framework.TestSuite{ 46 Component: "Connect", 47 CanRunLocal: true, 48 Consul: true, 49 Cases: []framework.TestCase{ 50 new(ConnectE2ETest), 51 new(ConnectClientStateE2ETest), 52 }, 53 }) 54 55 framework.AddSuites(&framework.TestSuite{ 56 Component: "ConnectACLs", 57 CanRunLocal: false, 58 Consul: true, 59 Parallel: false, 60 Cases: []framework.TestCase{ 61 new(ConnectACLsE2ETest), 62 }, 63 }) 64 } 65 66 func (tc *ConnectE2ETest) BeforeAll(f *framework.F) { 67 e2eutil.WaitForLeader(f.T(), tc.Nomad()) 68 e2eutil.WaitForNodesReady(f.T(), tc.Nomad(), 2) 69 } 70 71 func (tc *ConnectE2ETest) AfterEach(f *framework.F) { 72 if os.Getenv("NOMAD_TEST_SKIPCLEANUP") == "1" { 73 return 74 } 75 76 for _, id := range tc.jobIds { 77 tc.Nomad().Jobs().Deregister(id, true, nil) 78 } 79 tc.jobIds = []string{} 80 tc.Nomad().System().GarbageCollect() 81 } 82 83 func connectJobID() string { 84 return "connect" + uuid.Generate()[0:8] 85 } 86 87 // TestConnectDemo tests the demo job file used in Connect Integration examples. 88 func (tc *ConnectE2ETest) TestConnectDemo(f *framework.F) { 89 t := f.T() 90 91 jobID := connectJobID() 92 tc.jobIds = append(tc.jobIds, jobID) 93 94 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectJob, jobID, "") 95 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 96 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 97 } 98 99 // TestConnectCustomSidecarExposed tests that a connect sidecar with custom task 100 // definition can also make use of the expose service check feature. 101 func (tc *ConnectE2ETest) TestConnectCustomSidecarExposed(f *framework.F) { 102 t := f.T() 103 104 jobID := connectJobID() 105 tc.jobIds = append(tc.jobIds, jobID) 106 107 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectCustomProxyExposed, jobID, "") 108 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 109 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 110 } 111 112 // TestConnectNativeDemo tests the demo job file used in Connect Native Integration examples. 113 func (tc *ConnectE2ETest) TestConnectNativeDemo(f *framework.F) { 114 t := f.T() 115 116 jobID := connectJobID() 117 tc.jobIds = append(tc.jobIds, jobID) 118 119 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectNativeJob, jobID, "") 120 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 121 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 122 } 123 124 func (tc *ConnectE2ETest) TestConnectIngressGatewayDemo(f *framework.F) { 125 t := f.T() 126 127 jobID := connectJobID() 128 tc.jobIds = append(tc.jobIds, jobID) 129 130 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectIngressGateway, jobID, "") 131 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 132 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 133 } 134 135 func (tc *ConnectE2ETest) TestConnectMultiIngressGatewayDemo(f *framework.F) { 136 t := f.T() 137 138 jobID := connectJobID() 139 tc.jobIds = append(tc.jobIds, jobID) 140 141 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectMultiIngressGateway, jobID, "") 142 143 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 144 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 145 } 146 147 func (tc *ConnectE2ETest) TestConnectTerminatingGatewayDemo(f *framework.F) { 148 149 t := f.T() 150 151 jobID := connectJobID() 152 tc.jobIds = append(tc.jobIds, jobID) 153 154 allocs := e2eutil.RegisterAndWaitForAllocs(t, tc.Nomad(), demoConnectTerminatingGateway, jobID, "") 155 156 allocIDs := e2eutil.AllocIDsFromAllocationListStubs(allocs) 157 e2eutil.WaitForAllocsRunning(t, tc.Nomad(), allocIDs) 158 }