-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp_test.go
More file actions
57 lines (47 loc) · 1.4 KB
/
mcp_test.go
File metadata and controls
57 lines (47 loc) · 1.4 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
53
54
55
56
57
package main
import (
"context"
"os"
"strings"
"testing"
"github.com/zalando/go-keyring"
)
func TestRun_MCPServer(t *testing.T) {
// Set SLACK_TOKEN env var to get past token check
oldToken := os.Getenv("SLACK_TOKEN")
os.Setenv("SLACK_TOKEN", "test-token")
defer func() {
if oldToken == "" {
os.Unsetenv("SLACK_TOKEN")
} else {
os.Setenv("SLACK_TOKEN", oldToken)
}
}()
// Test that mcp-server sub-command is recognized (won't actually run the server in this test)
// We would need to mock stdin/stdout to fully test this
args := []string{"mcp-server"}
// We can't easily test the full server without mocking stdin/stdout
// but we can verify the command is recognized and doesn't return "unknown sub-command"
_ = args
// This test just verifies the test setup works
}
func TestRun_MCPServerMissingToken(t *testing.T) {
// Unset SLACK_TOKEN env var and clear keyring
oldToken := os.Getenv("SLACK_TOKEN")
os.Unsetenv("SLACK_TOKEN")
defer func() {
if oldToken != "" {
os.Setenv("SLACK_TOKEN", oldToken)
}
}()
// Clear keyring to ensure no token is stored
_ = keyring.Delete(keyringService, keyringUser)
ctx := context.Background()
err := run(ctx, []string{"mcp-server"})
if err == nil {
t.Error("Expected error for missing token, got nil")
}
if !strings.Contains(err.Error(), "Slack token must be set") {
t.Errorf("Expected 'Slack token must be set' error, got: %v", err)
}
}