Skip to content

Commit 895fac8

Browse files
address comments
1 parent 64e95b8 commit 895fac8

File tree

7 files changed

+13
-16
lines changed

7 files changed

+13
-16
lines changed

CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Environment variables:
5757
- Do not remove comments added by someone else than yourself.
5858
- Errors returned by functions should always be checked unless in test files.
5959
- Terminology: in user-facing CLI/help/docs, prefer `emulator` over `container`/`runtime`; use `container`/`runtime` only for internal implementation details.
60+
- Avoid package-level global variables. Use constructor functions that return fresh instances and inject dependencies explicitly. This keeps packages testable in isolation and prevents shared mutable state between tests.
6061

6162
# Testing
6263

internal/auth/token_storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type authTokenStorage struct {
3232
ring keyring.Keyring
3333
}
3434

35-
func NewTokenStorage(forceFileBackend bool) (AuthTokenStorage, error) {
35+
func NewTokenStorage(forceFileKeyring bool) (AuthTokenStorage, error) {
3636
configDir, err := config.ConfigDir()
3737
if err != nil {
3838
return nil, err
@@ -46,7 +46,7 @@ func NewTokenStorage(forceFileBackend bool) (AuthTokenStorage, error) {
4646
},
4747
}
4848

49-
if forceFileBackend {
49+
if forceFileKeyring {
5050
keyringConfig.AllowedBackends = []keyring.BackendType{keyring.FileBackend}
5151
}
5252

internal/container/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import (
1717
"github.com/localstack/lstk/internal/runtime"
1818
)
1919

20-
func Start(ctx context.Context, rt runtime.Runtime, sink output.Sink, platformClient api.PlatformAPI, authToken string, forceFileBackend bool, webAppURL string, interactive bool) error {
20+
func Start(ctx context.Context, rt runtime.Runtime, sink output.Sink, platformClient api.PlatformAPI, authToken string, forceFileKeyring bool, webAppURL string, interactive bool) error {
2121
if err := rt.IsHealthy(ctx); err != nil {
2222
rt.EmitUnhealthyError(sink, err)
2323
return output.NewSilentError(fmt.Errorf("runtime not healthy: %w", err))
2424
}
2525

26-
tokenStorage, err := auth.NewTokenStorage(forceFileBackend)
26+
tokenStorage, err := auth.NewTokenStorage(forceFileKeyring)
2727
if err != nil {
2828
return fmt.Errorf("failed to initialize token storage: %w", err)
2929
}

internal/ui/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (s programSender) Send(msg any) {
2626
s.p.Send(msg)
2727
}
2828

29-
func Run(parentCtx context.Context, rt runtime.Runtime, version string, platformClient api.PlatformAPI, authToken string, forceFileBackend bool, webAppURL string) error {
29+
func Run(parentCtx context.Context, rt runtime.Runtime, version string, platformClient api.PlatformAPI, authToken string, forceFileKeyring bool, webAppURL string) error {
3030
ctx, cancel := context.WithCancel(parentCtx)
3131
defer cancel()
3232

@@ -47,7 +47,7 @@ func Run(parentCtx context.Context, rt runtime.Runtime, version string, platform
4747
go func() {
4848
var err error
4949
defer func() { runErrCh <- err }()
50-
err = container.Start(ctx, rt, output.NewTUISink(programSender{p: p}), platformClient, authToken, forceFileBackend, webAppURL, true)
50+
err = container.Start(ctx, rt, output.NewTUISink(programSender{p: p}), platformClient, authToken, forceFileKeyring, webAppURL, true)
5151
if err != nil {
5252
if errors.Is(err, context.Canceled) {
5353
return

internal/ui/run_login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/localstack/lstk/internal/output"
1212
)
1313

14-
func RunLogin(parentCtx context.Context, version string, platformClient api.PlatformAPI, authToken string, forceFileBackend bool, webAppURL string) error {
14+
func RunLogin(parentCtx context.Context, version string, platformClient api.PlatformAPI, authToken string, forceFileKeyring bool, webAppURL string) error {
1515
ctx, cancel := context.WithCancel(parentCtx)
1616
defer cancel()
1717

@@ -20,7 +20,7 @@ func RunLogin(parentCtx context.Context, version string, platformClient api.Plat
2020
runErrCh := make(chan error, 1)
2121

2222
go func() {
23-
tokenStorage, err := auth.NewTokenStorage(forceFileBackend)
23+
tokenStorage, err := auth.NewTokenStorage(forceFileKeyring)
2424
if err != nil {
2525
runErrCh <- err
2626
p.Send(runErrMsg{err: err})

internal/ui/run_login_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,6 @@ func TestLoginFlow_DeviceFlowCancelWithCtrlC(t *testing.T) {
181181
mockServer := createMockAPIServer(t, "", false)
182182
defer mockServer.Close()
183183

184-
t.Setenv("LSTK_API_ENDPOINT", mockServer.URL)
185-
t.Setenv("LOCALSTACK_AUTH_TOKEN", "")
186-
env.Init()
187-
188184
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
189185
defer cancel()
190186

@@ -194,11 +190,11 @@ func TestLoginFlow_DeviceFlowCancelWithCtrlC(t *testing.T) {
194190

195191
tm := teatest.NewTestModel(t, NewApp("test", "", "", cancel), teatest.WithInitialTermSize(120, 40))
196192
sender := testModelSender{tm: tm}
197-
platformClient := api.NewPlatformClient()
193+
platformClient := api.NewPlatformClient(mockServer.URL)
198194

199195
errCh := make(chan error, 1)
200196
go func() {
201-
a := auth.New(output.NewTUISink(sender), platformClient, mockStorage, true)
197+
a := auth.New(output.NewTUISink(sender), platformClient, mockStorage, "", mockServer.URL, true)
202198
_, err := a.GetToken(ctx)
203199
errCh <- err
204200
if err != nil && !errors.Is(err, context.Canceled) {

internal/ui/run_logout.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/localstack/lstk/internal/output"
1212
)
1313

14-
func RunLogout(parentCtx context.Context, platformClient api.PlatformAPI, authToken string, forceFileBackend bool) error {
14+
func RunLogout(parentCtx context.Context, platformClient api.PlatformAPI, authToken string, forceFileKeyring bool) error {
1515
_, cancel := context.WithCancel(parentCtx)
1616
defer cancel()
1717

@@ -20,7 +20,7 @@ func RunLogout(parentCtx context.Context, platformClient api.PlatformAPI, authTo
2020
runErrCh := make(chan error, 1)
2121

2222
go func() {
23-
tokenStorage, err := auth.NewTokenStorage(forceFileBackend)
23+
tokenStorage, err := auth.NewTokenStorage(forceFileKeyring)
2424
if err != nil {
2525
runErrCh <- err
2626
p.Send(runErrMsg{err: err})

0 commit comments

Comments
 (0)