Skip to content

Commit

Permalink
♻️ Make internal tests parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
elgohr committed Dec 25, 2023
1 parent 04c4a4d commit a4e5cd6
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions localstack_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (
)

func TestInstance_Start_Fails(t *testing.T) {
for _, tt := range [...]struct {
t.Parallel()
for _, scenario := range [...]struct {
when string
given func(f *internalfakes.FakeDockerClient) *Instance
then func(t *testing.T, err error, f *internalfakes.FakeDockerClient)
Expand Down Expand Up @@ -108,7 +109,7 @@ func TestInstance_Start_Fails(t *testing.T) {
AttachStdout: true,
AttachStderr: true,
}, config)
pm := nat.PortMap{}
pm := make(nat.PortMap, len(AvailableServices))
for service := range AvailableServices {
pm[nat.Port(service.Port)] = []nat.PortBinding{{HostIP: "0.0.0.0", HostPort: ""}}
}
Expand Down Expand Up @@ -165,15 +166,18 @@ func TestInstance_Start_Fails(t *testing.T) {
},
},
} {
t.Run(tt.when, func(t *testing.T) {
s := scenario
t.Run(s.when, func(t *testing.T) {
t.Parallel()
f := &internalfakes.FakeDockerClient{}
f.ContainerLogsReturns(io.NopCloser(strings.NewReader("")), nil)
tt.then(t, tt.given(f).Start(), f)
s.then(t, s.given(f).Start(), f)
})
}
}

func TestInstance_StartWithContext_Fails_Stop_AfterTest(t *testing.T) {
t.Parallel()
f := &internalfakes.FakeDockerClient{}
ctx, cancel := context.WithCancel(context.Background())
cancel()
Expand All @@ -183,14 +187,16 @@ func TestInstance_StartWithContext_Fails_Stop_AfterTest(t *testing.T) {
}

func TestInstance_Stop_Fails(t *testing.T) {
t.Parallel()
f := &internalfakes.FakeDockerClient{}
f.ContainerStopReturns(errors.New("can't stop"))
i := &Instance{cli: f, log: logrus.StandardLogger(), containerId: "something"}
require.EqualError(t, i.Stop(), "can't stop")
}

func TestInstance_checkAvailable_Session_Fails(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
t.Parallel()
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond)
defer cancel()
require.NoError(t, os.Setenv("AWS_STS_REGIONAL_ENDPOINTS", "FAILURE"))
defer func() {
Expand All @@ -201,6 +207,7 @@ func TestInstance_checkAvailable_Session_Fails(t *testing.T) {
}

func TestInstance_waitToBeAvailable_Context_Expired(t *testing.T) {
t.Parallel()
ctx, cancel := context.WithCancel(context.Background())
cancel()
i := &Instance{log: logrus.StandardLogger()}
Expand Down

0 comments on commit a4e5cd6

Please sign in to comment.