Skip to content

Commit d8df55c

Browse files
committed
Fix linting & paralellize tests
1 parent 5ab0285 commit d8df55c

6 files changed

Lines changed: 22 additions & 5 deletions

File tree

cmd/snapshot.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The destination must be a file path. Use a path prefix to save locally:
3838
3939
Cloud destinations are not yet supported.`,
4040
Args: cobra.MaximumNArgs(1),
41-
PreRunE: initConfig,
41+
PreRunE: initConfig(nil),
4242
RunE: func(cmd *cobra.Command, args []string) error {
4343
var destArg string
4444
if len(args) > 0 {

internal/snapshot/client_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
func TestStateClient_ExportState_OK(t *testing.T) {
17+
t.Parallel()
1718
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1819
assert.Equal(t, "/_localstack/pods/state", r.URL.Path)
1920
assert.Equal(t, http.MethodGet, r.Method)
@@ -33,6 +34,7 @@ func TestStateClient_ExportState_OK(t *testing.T) {
3334
}
3435

3536
func TestStateClient_ExportState_ServerError(t *testing.T) {
37+
t.Parallel()
3638
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
3739
w.WriteHeader(http.StatusInternalServerError)
3840
}))
@@ -45,6 +47,7 @@ func TestStateClient_ExportState_ServerError(t *testing.T) {
4547
}
4648

4749
func TestStateClient_ExportState_NotFound(t *testing.T) {
50+
t.Parallel()
4851
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
4952
w.WriteHeader(http.StatusNotFound)
5053
}))
@@ -57,6 +60,7 @@ func TestStateClient_ExportState_NotFound(t *testing.T) {
5760
}
5861

5962
func TestStateClient_ExportState_ConnectionRefused(t *testing.T) {
63+
t.Parallel()
6064
// Bind then immediately close to get a port that refuses connections.
6165
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
6266
addr := srv.URL
@@ -69,6 +73,7 @@ func TestStateClient_ExportState_ConnectionRefused(t *testing.T) {
6973
}
7074

7175
func TestStateClient_ExportState_ContextCancelled(t *testing.T) {
76+
t.Parallel()
7277
started := make(chan struct{})
7378
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
7479
close(started)
@@ -94,6 +99,7 @@ func TestStateClient_ExportState_ContextCancelled(t *testing.T) {
9499
}
95100

96101
func TestStateClient_ExportState_LargeBody(t *testing.T) {
102+
t.Parallel()
97103
const size = 1 << 20 // 1 MB
98104
payload := strings.Repeat("X", size)
99105

internal/snapshot/destination_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func TestParseDestination(t *testing.T) {
14+
t.Parallel()
1415
wd, err := os.Getwd()
1516
require.NoError(t, err)
1617
home, err := os.UserHomeDir()
@@ -57,6 +58,7 @@ func TestParseDestination(t *testing.T) {
5758

5859
for _, tc := range tests {
5960
t.Run(tc.input, func(t *testing.T) {
61+
t.Parallel()
6062
got, err := snapshot.ParseDestination(tc.input)
6163
if tc.wantErr != "" {
6264
require.Error(t, err)

internal/snapshot/save.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ func Save(ctx context.Context, rt runtime.Runtime, containers []config.Container
1919
return output.NewSilentError(fmt.Errorf("runtime not healthy: %w", err))
2020
}
2121

22-
running, err := container.AnyRunning(ctx, rt, containers)
22+
runningContainers, err := container.RunningEmulators(ctx, rt, containers)
2323
if err != nil {
2424
return fmt.Errorf("checking emulator status: %w", err)
2525
}
26-
if !running {
26+
if len(runningContainers) == 0 {
2727
sink.Emit(output.ErrorEvent{
2828
Title: "LocalStack is not running",
2929
Actions: []output.ErrorAction{

internal/snapshot/save_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func healthyRunningMock(t *testing.T) *runtime.MockRuntime {
5252
var awsContainers = []config.ContainerConfig{{Type: config.EmulatorAWS}}
5353

5454
func TestSave_Success(t *testing.T) {
55+
t.Parallel()
5556
dir := t.TempDir()
5657
dest := filepath.Join(dir, "snap")
5758
exporter := &fakeExporter{body: []byte("ZIP_DATA")}
@@ -89,6 +90,7 @@ func TestSave_Success(t *testing.T) {
8990
}
9091

9192
func TestSave_EmulatorNotRunning(t *testing.T) {
93+
t.Parallel()
9294
ctrl := gomock.NewController(t)
9395
mockRT := runtime.NewMockRuntime(ctrl)
9496
mockRT.EXPECT().IsHealthy(gomock.Any()).Return(nil)
@@ -118,6 +120,7 @@ func TestSave_EmulatorNotRunning(t *testing.T) {
118120
}
119121

120122
func TestSave_UnhealthyRuntime(t *testing.T) {
123+
t.Parallel()
121124
ctrl := gomock.NewController(t)
122125
mockRT := runtime.NewMockRuntime(ctrl)
123126
mockRT.EXPECT().IsHealthy(gomock.Any()).Return(fmt.Errorf("docker unavailable"))
@@ -133,6 +136,7 @@ func TestSave_UnhealthyRuntime(t *testing.T) {
133136
}
134137

135138
func TestSave_ExporterError(t *testing.T) {
139+
t.Parallel()
136140
dir := t.TempDir()
137141
dest := filepath.Join(dir, "snap")
138142
exporter := &fakeExporter{err: fmt.Errorf("connection refused")}
@@ -147,6 +151,7 @@ func TestSave_ExporterError(t *testing.T) {
147151
}
148152

149153
func TestSave_DestinationDirNotExist(t *testing.T) {
154+
t.Parallel()
150155
dest := "/no/such/dir/snap"
151156
exporter := &fakeExporter{body: []byte("ZIP_DATA")}
152157
sink := output.NewPlainSink(io.Discard)
@@ -157,6 +162,7 @@ func TestSave_DestinationDirNotExist(t *testing.T) {
157162
}
158163

159164
func TestSave_OverwritesExistingFile(t *testing.T) {
165+
t.Parallel()
160166
dir := t.TempDir()
161167
path := filepath.Join(dir, "snap")
162168
require.NoError(t, os.WriteFile(path, []byte("OLD"), 0600))
@@ -174,6 +180,7 @@ func TestSave_OverwritesExistingFile(t *testing.T) {
174180
}
175181

176182
func TestSave_ContextCancelled(t *testing.T) {
183+
t.Parallel()
177184
ctx, cancel := context.WithCancel(context.Background())
178185
cancel()
179186

test/integration/snapshot_save_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,11 @@ func TestSnapshotSaveOverwritesExistingFile(t *testing.T) {
140140
// TestSnapshotSaveBareNameRejected does not require Docker: destination
141141
// parsing fails before the runtime is ever touched.
142142
func TestSnapshotSaveBareNameRejected(t *testing.T) {
143+
t.Parallel()
143144
ctx := testContext(t)
144145
dir := t.TempDir()
145146

146-
_, stderr, err := runLstk(t, ctx, dir, nil, "--non-interactive", "snapshot", "save", "my-pod")
147+
_, stderr, err := runLstk(t, ctx, dir, testEnvWithHome(t.TempDir(), ""), "--non-interactive", "snapshot", "save", "my-pod")
147148
requireExitCode(t, 1, err)
148149
assert.Contains(t, stderr, "not yet supported")
149150
assert.Contains(t, stderr, "./my-snapshot")
@@ -152,10 +153,11 @@ func TestSnapshotSaveBareNameRejected(t *testing.T) {
152153
// TestSnapshotSaveCloudURIRejected does not require Docker: destination
153154
// parsing fails before the runtime is ever touched.
154155
func TestSnapshotSaveCloudURIRejected(t *testing.T) {
156+
t.Parallel()
155157
ctx := testContext(t)
156158
dir := t.TempDir()
157159

158-
_, stderr, err := runLstk(t, ctx, dir, nil, "--non-interactive", "snapshot", "save", "cloud://my-pod")
160+
_, stderr, err := runLstk(t, ctx, dir, testEnvWithHome(t.TempDir(), ""), "--non-interactive", "snapshot", "save", "cloud://my-pod")
159161
requireExitCode(t, 1, err)
160162
assert.Contains(t, stderr, "not yet supported")
161163
}

0 commit comments

Comments
 (0)