@@ -2,18 +2,13 @@ package integration_test
22
33import (
44 "context"
5- "crypto/tls"
6- "fmt"
75 "net"
8- "net/http"
96 "os"
107 "path/filepath"
11- "strconv"
128 "strings"
139 "testing"
1410
1511 "github.com/docker/docker/api/types/container"
16- "github.com/docker/go-connections/nat"
1712 "github.com/localstack/lstk/test/integration/env"
1813 "github.com/stretchr/testify/assert"
1914 "github.com/stretchr/testify/require"
@@ -164,66 +159,36 @@ func TestStartCommandSetsUpContainerCorrectly(t *testing.T) {
164159 assert .Equal (t , containerName , envVars ["MAIN_CONTAINER_NAME" ])
165160 assert .NotEmpty (t , envVars ["LOCALSTACK_AUTH_TOKEN" ])
166161 })
162+ }
167163
168- t .Run ("docker socket mount" , func (t * testing.T ) {
169- if ! strings .HasPrefix (dockerClient .DaemonHost (), "unix://" ) {
170- t .Skip ("Docker daemon is not reachable via unix socket" )
171- }
172-
173- assert .True (t , hasBindTarget (inspect .HostConfig .Binds , "/var/run/docker.sock" ),
174- "expected Docker socket bind mount to /var/run/docker.sock, got: %v" , inspect .HostConfig .Binds )
175-
176- envVars := containerEnvToMap (inspect .Config .Env )
177- assert .Equal (t , "unix:///var/run/docker.sock" , envVars ["DOCKER_HOST" ])
178- })
164+ func TestStartCommandPassesCIAndLocalStackEnvVars (t * testing.T ) {
165+ requireDocker (t )
166+ _ = env .Require (t , env .AuthToken )
179167
180- t .Run ("service port range" , func (t * testing.T ) {
181- for p := 4510 ; p <= 4559 ; p ++ {
182- port := nat .Port (fmt .Sprintf ("%d/tcp" , p ))
183- bindings := inspect .HostConfig .PortBindings [port ]
184- if assert .NotEmpty (t , bindings , "port %d/tcp should be bound" , p ) {
185- assert .Equal (t , strconv .Itoa (p ), bindings [0 ].HostPort )
186- }
187- }
188- })
168+ cleanup ()
169+ t .Cleanup (cleanup )
189170
190- t .Run ("main port" , func (t * testing.T ) {
191- mainBindings := inspect .HostConfig .PortBindings [nat .Port ("4566/tcp" )]
192- require .NotEmpty (t , mainBindings , "port 4566/tcp should be bound" )
193- assert .Equal (t , "4566" , mainBindings [0 ].HostPort )
194- })
171+ t .Setenv ("CI" , "true" )
172+ t .Setenv ("LOCALSTACK_DISABLE_EVENTS" , "1" )
173+ t .Setenv ("LOCALSTACK_AUTH_TOKEN" , "host-token" )
195174
196- t .Run ("https port" , func (t * testing.T ) {
197- httpsBindings := inspect .HostConfig .PortBindings [nat .Port ("443/tcp" )]
198- require .NotEmpty (t , httpsBindings , "port 443/tcp should be bound" )
199- assert .Equal (t , "443" , httpsBindings [0 ].HostPort )
200- })
175+ mockServer := createMockLicenseServer (true )
176+ defer mockServer .Close ()
201177
202- t . Run ( "volume mount" , func ( t * testing. T ) {
203- assert . True (t , hasBindTarget ( inspect . HostConfig . Binds , "/var/lib/localstack" ),
204- "expected volume bind mount to /var/lib/localstack, got : %v " , inspect . HostConfig . Binds )
205- } )
178+ ctx := testContext ( t )
179+ _ , stderr , err := runLstk (t , ctx , "" , env . With ( env . APIEndpoint , mockServer . URL ) , "start" )
180+ require . NoError ( t , err , "lstk start failed : %s " , stderr )
181+ requireExitCode ( t , 0 , err )
206182
207- t .Run ("http health endpoint" , func (t * testing.T ) {
208- resp , err := http .Get ("http://localhost.localstack.cloud:4566/_localstack/health" )
209- require .NoError (t , err )
210- defer resp .Body .Close ()
211- assert .Equal (t , http .StatusOK , resp .StatusCode )
212- })
183+ inspect , err := dockerClient .ContainerInspect (ctx , containerName )
184+ require .NoError (t , err , "failed to inspect container" )
185+ require .True (t , inspect .State .Running )
213186
214- t .Run ("https health endpoint" , func (t * testing.T ) {
215- // LS certificate is not in system trust store
216- // But cert validity is out of scope here: use InsecureSkipVerify
217- client := & http.Client {
218- Transport : & http.Transport {
219- TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
220- },
221- }
222- resp , err := client .Get ("https://localhost.localstack.cloud/_localstack/health" )
223- require .NoError (t , err )
224- defer resp .Body .Close ()
225- assert .Equal (t , http .StatusOK , resp .StatusCode )
226- })
187+ envVars := containerEnvToMap (inspect .Config .Env )
188+ assert .Equal (t , "true" , envVars ["CI" ])
189+ assert .Equal (t , "1" , envVars ["LOCALSTACK_DISABLE_EVENTS" ])
190+ assert .NotEmpty (t , envVars ["LOCALSTACK_AUTH_TOKEN" ])
191+ assert .NotEqual (t , "host-token" , envVars ["LOCALSTACK_AUTH_TOKEN" ], "host LOCALSTACK_AUTH_TOKEN should not be passed through" )
227192}
228193
229194// containerEnvToMap converts a Docker container's []string env to a map.
@@ -236,17 +201,6 @@ func containerEnvToMap(envList []string) map[string]string {
236201 return m
237202}
238203
239- // hasBindTarget checks if any bind mount targets the given container path.
240- func hasBindTarget (binds []string , containerPath string ) bool {
241- for _ , b := range binds {
242- parts := strings .Split (b , ":" )
243- if len (parts ) >= 2 && parts [1 ] == containerPath {
244- return true
245- }
246- }
247- return false
248- }
249-
250204func cleanup () {
251205 ctx := context .Background ()
252206 _ = dockerClient .ContainerStop (ctx , containerName , container.StopOptions {})
0 commit comments