-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp_test.go
More file actions
186 lines (162 loc) · 4.93 KB
/
mcp_test.go
File metadata and controls
186 lines (162 loc) · 4.93 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package main
import (
"context"
"os"
"strings"
"testing"
)
func TestRun_MCPServer(t *testing.T) {
// Set JIRA_HOST and JIRA_TOKEN env vars to get past token check
oldHost := os.Getenv("JIRA_HOST")
oldToken := os.Getenv("JIRA_TOKEN")
os.Setenv("JIRA_HOST", "test.atlassian.net")
os.Setenv("JIRA_TOKEN", "test-token")
defer func() {
if oldHost == "" {
os.Unsetenv("JIRA_HOST")
} else {
os.Setenv("JIRA_HOST", oldHost)
}
if oldToken == "" {
os.Unsetenv("JIRA_TOKEN")
} else {
os.Setenv("JIRA_TOKEN", oldToken)
}
}()
// Test that mcp-server sub-command is recognized
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_MCPServerMissingConfig(t *testing.T) {
// Unset JIRA_HOST env var
oldHost := os.Getenv("JIRA_HOST")
os.Unsetenv("JIRA_HOST")
defer func() {
if oldHost != "" {
os.Setenv("JIRA_HOST", oldHost)
}
}()
ctx := context.Background()
err := run(ctx, []string{"mcp-server"})
if err == nil {
t.Error("Expected error for missing configuration, got nil")
return
}
if !strings.Contains(err.Error(), "JIRA host must be configured") {
t.Errorf("Expected 'JIRA host must be configured' error, got: %v", err)
}
}
func TestRun_AttachFileMissingArgs(t *testing.T) {
ctx := context.Background()
// Test with no arguments
err := run(ctx, []string{"attach-file"})
if err == nil {
t.Error("Expected error for missing arguments, got nil")
}
if !strings.Contains(err.Error(), "usage: jira attach-file") {
t.Errorf("Expected usage error, got: %v", err)
}
// Test with only issue key
err = run(ctx, []string{"attach-file", "TEST-123"})
if err == nil {
t.Error("Expected error for missing file path, got nil")
}
if !strings.Contains(err.Error(), "usage: jira attach-file") {
t.Errorf("Expected usage error, got: %v", err)
}
}
func TestRun_AttachFileNonExistentFile(t *testing.T) {
// Set JIRA_HOST and JIRA_TOKEN env vars
oldHost := os.Getenv("JIRA_HOST")
oldToken := os.Getenv("JIRA_TOKEN")
os.Setenv("JIRA_HOST", "test.atlassian.net")
os.Setenv("JIRA_TOKEN", "test-token")
defer func() {
if oldHost == "" {
os.Unsetenv("JIRA_HOST")
} else {
os.Setenv("JIRA_HOST", oldHost)
}
if oldToken == "" {
os.Unsetenv("JIRA_TOKEN")
} else {
os.Setenv("JIRA_TOKEN", oldToken)
}
}()
ctx := context.Background()
err := run(ctx, []string{"attach-file", "TEST-123", "/tmp/nonexistent-file-12345.txt"})
if err == nil {
t.Error("Expected error for non-existent file, got nil")
}
if !strings.Contains(err.Error(), "failed to open file") {
t.Errorf("Expected 'failed to open file' error, got: %v", err)
}
}
func TestRun_AssignIssueMissingArgs(t *testing.T) {
ctx := context.Background()
// Test with no arguments
err := run(ctx, []string{"assign-issue"})
if err == nil {
t.Error("Expected error for missing arguments, got nil")
}
if !strings.Contains(err.Error(), "usage: jira assign-issue") {
t.Errorf("Expected usage error, got: %v", err)
}
// Test with only issue key
err = run(ctx, []string{"assign-issue", "TEST-123"})
if err == nil {
t.Error("Expected error for missing assignee, got nil")
}
if !strings.Contains(err.Error(), "usage: jira assign-issue") {
t.Errorf("Expected usage error, got: %v", err)
}
}
func TestRun_AddIssueToSprintMissingArgs(t *testing.T) {
ctx := context.Background()
// Test with no arguments
err := run(ctx, []string{"add-issue-to-sprint"})
if err == nil {
t.Error("Expected error for missing arguments, got nil")
}
if !strings.Contains(err.Error(), "usage: jira add-issue-to-sprint") {
t.Errorf("Expected usage error, got: %v", err)
}
}
func TestRun_CreateIssueMissingArgs(t *testing.T) {
ctx := context.Background()
// Test with no arguments
err := run(ctx, []string{"create-issue"})
if err == nil {
t.Error("Expected error for missing arguments, got nil")
}
if !strings.Contains(err.Error(), "usage: jira create-issue") {
t.Errorf("Expected usage error, got: %v", err)
}
// Test with only project
err = run(ctx, []string{"create-issue", "PROJ"})
if err == nil {
t.Error("Expected error for missing arguments, got nil")
}
if !strings.Contains(err.Error(), "usage: jira create-issue") {
t.Errorf("Expected usage error, got: %v", err)
}
// Test with project and issue type
err = run(ctx, []string{"create-issue", "PROJ", "Task"})
if err == nil {
t.Error("Expected error for missing arguments, got nil")
}
if !strings.Contains(err.Error(), "usage: jira create-issue") {
t.Errorf("Expected usage error, got: %v", err)
}
// Test with project, issue type, and title
err = run(ctx, []string{"create-issue", "PROJ", "Task", "My Title"})
if err == nil {
t.Error("Expected error for missing arguments, got nil")
}
if !strings.Contains(err.Error(), "usage: jira create-issue") {
t.Errorf("Expected usage error, got: %v", err)
}
}