-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathlogout_test.go
More file actions
52 lines (40 loc) · 1.44 KB
/
logout_test.go
File metadata and controls
52 lines (40 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package integration_test
import (
"context"
"os/exec"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zalando/go-keyring"
)
func TestLogoutCommandRemovesToken(t *testing.T) {
// Clean up any existing token
_ = keyring.Delete(keyringService, keyringUser)
t.Cleanup(func() {
_ = keyring.Delete(keyringService, keyringUser)
})
// Store a token in keyring
err := keyring.Set(keyringService, keyringUser, "test-token")
require.NoError(t, err, "failed to store token in keyring")
// Run logout command
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, binaryPath(), "logout")
output, err := cmd.CombinedOutput()
require.NoError(t, err, "lstk logout failed: %s", output)
assert.Contains(t, string(output), "Logged out successfully")
// Verify token was removed
_, err = keyring.Get(keyringService, keyringUser)
assert.Error(t, err, "token should be removed from keyring")
}
func TestLogoutCommandSucceedsWhenNoToken(t *testing.T) {
// Ensure no token exists
_ = keyring.Delete(keyringService, keyringUser)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, binaryPath(), "logout")
output, err := cmd.CombinedOutput()
// Should succeed even if no token
require.NoError(t, err, "lstk logout should succeed even with no token: %s", output)
}