Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/localstack/lstk/internal/awscli"
"github.com/localstack/lstk/internal/awsconfig"
"github.com/localstack/lstk/internal/config"
"github.com/localstack/lstk/internal/container"
"github.com/localstack/lstk/internal/endpoint"
"github.com/localstack/lstk/internal/env"
"github.com/localstack/lstk/internal/output"
Expand Down Expand Up @@ -60,11 +61,11 @@ Examples:
return output.NewSilentError(fmt.Errorf("runtime not healthy: %w", err))
}

running, err := rt.IsRunning(cmd.Context(), awsContainer.Name())
runningName, err := container.ResolveRunningContainerName(cmd.Context(), rt, awsContainer)
if err != nil {
return fmt.Errorf("checking emulator status: %w", err)
}
if !running {
if runningName == "" {
sink.Emit(output.ErrorEvent{
Title: fmt.Sprintf("%s is not running", awsContainer.DisplayName()),
Actions: []output.ErrorAction{
Expand Down
4 changes: 2 additions & 2 deletions internal/container/running.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func StillRunningMessage(running []config.ContainerConfig) string {
func RunningEmulators(ctx context.Context, rt runtime.Runtime, containers []config.ContainerConfig) ([]config.ContainerConfig, error) {
var running []config.ContainerConfig
for _, c := range containers {
name, err := resolveRunningContainerName(ctx, rt, c)
name, err := ResolveRunningContainerName(ctx, rt, c)
if err != nil {
return nil, err
}
Expand All @@ -34,7 +34,7 @@ func RunningEmulators(ctx context.Context, rt runtime.Runtime, containers []conf
return running, nil
}

func resolveRunningContainerName(ctx context.Context, rt runtime.Runtime, c config.ContainerConfig) (string, error) {
func ResolveRunningContainerName(ctx context.Context, rt runtime.Runtime, c config.ContainerConfig) (string, error) {
running, err := rt.IsRunning(ctx, c.Name())
if err != nil {
return "", fmt.Errorf("checking %s running: %w", c.Name(), err)
Expand Down
2 changes: 1 addition & 1 deletion internal/container/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Status(ctx context.Context, rt runtime.Runtime, containers []config.Contain
defer cancel()

for _, c := range containers {
name, err := resolveRunningContainerName(ctx, rt, c)
name, err := ResolveRunningContainerName(ctx, rt, c)
if err != nil {
return fmt.Errorf("checking %s running: %w", c.Name(), err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/container/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func Stop(ctx context.Context, rt runtime.Runtime, sink output.Sink, containers

const stopTimeout = 30 * time.Second
for _, c := range containers {
name, err := resolveRunningContainerName(ctx, rt, c)
name, err := ResolveRunningContainerName(ctx, rt, c)
if err != nil {
return err
}
Expand Down
25 changes: 25 additions & 0 deletions test/integration/aws_cmd_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package integration_test

import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"testing"

"github.com/docker/docker/api/types/image"
"github.com/localstack/lstk/test/integration/env"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -275,6 +277,29 @@ func TestAWSCommandHintsSetupCommandWhenProfileMissing(t *testing.T) {
assert.Contains(t, stdout, "lstk setup aws")
}

func TestAWSCommandWorksWithExternalContainer(t *testing.T) {
requireDocker(t)
cleanup()
t.Cleanup(cleanup)

ctx := testContext(t)

const fakeImage = "localstack/localstack-pro:test-fake"
require.NoError(t, dockerClient.ImageTag(ctx, testImage, fakeImage))
t.Cleanup(func() {
_, _ = dockerClient.ImageRemove(context.Background(), fakeImage, image.RemoveOptions{})
})

startExternalContainer(t, ctx, fakeImage, "localstack-main", "4566")

fakeDir := writeFakeAWS(t)
e := env.With(env.DisableEvents, "1").With("PATH", fakeDir).With(env.Home, t.TempDir())

stdout, stderr, err := runLstk(t, ctx, t.TempDir(), e, "aws", "s3", "ls")
require.NoError(t, err, "lstk aws should work with externally-named container: %s", stderr)
assert.Contains(t, stdout, "ENDPOINT:http://")
}

func TestAWSCommandSuppressesHintWhenProfileExists(t *testing.T) {
requireDocker(t)
cleanup()
Expand Down
Loading