-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_show_test.go
More file actions
304 lines (250 loc) · 8.61 KB
/
cmd_show_test.go
File metadata and controls
304 lines (250 loc) · 8.61 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package main
import (
"bytes"
"context"
"path/filepath"
"strings"
"testing"
)
func TestShowCommand(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "mint-issues.yaml")
t.Setenv("MINT_STORE_FILE", filePath)
// Create issue directly via Store
store, err := LoadStore(filePath)
if err != nil {
t.Fatalf("failed to load store: %v", err)
}
issue, err := store.AddIssue("Test show issue")
if err != nil {
t.Fatalf("failed to add issue: %v", err)
}
if err := store.Save(filePath); err != nil {
t.Fatalf("failed to save store: %v", err)
}
// Test show command
cmd := newCommand()
var buf bytes.Buffer
cmd.Writer = &buf
err = cmd.Run(context.Background(), []string{"mint", "show", issue.ID})
if err != nil {
t.Fatalf("show command failed: %v", err)
}
output := stripANSI(buf.String())
if !strings.Contains(output, "ID "+issue.ID) {
t.Errorf("expected output to contain 'ID %s', got: %s", issue.ID, output)
}
if !strings.Contains(output, "Title Test show issue") {
t.Errorf("expected output to contain 'Title Test show issue', got: %s", output)
}
if !strings.Contains(output, "Status open") {
t.Errorf("expected output to contain 'Status open', got: %s", output)
}
}
func TestShowCommandNonExistent(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "mint-issues.yaml")
cmd := newCommand()
var buf bytes.Buffer
cmd.Writer = &buf
t.Setenv("MINT_STORE_FILE", filePath)
err := cmd.Run(context.Background(), []string{"mint", "show", "mint-nonexistent"})
if err == nil {
t.Error("expected error when showing non-existent issue")
}
}
func TestShowCommandWithComments(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "mint-issues.yaml")
t.Setenv("MINT_STORE_FILE", filePath)
store, _ := LoadStore(filePath)
issue, _ := store.AddIssue("Test issue with comments")
_ = store.AddComment(issue.ID, "First comment")
_ = store.AddComment(issue.ID, "Second comment")
_ = store.Save(filePath)
cmd := newCommand()
var buf bytes.Buffer
cmd.Writer = &buf
err := cmd.Run(context.Background(), []string{"mint", "show", issue.ID})
if err != nil {
t.Fatalf("show command failed: %v", err)
}
output := stripANSI(buf.String())
if !strings.Contains(output, "Comments") {
t.Errorf("expected output to contain 'Comments', got: %s", output)
}
if !strings.Contains(output, " First comment") {
t.Errorf("expected output to contain ' First comment', got: %s", output)
}
if !strings.Contains(output, " Second comment") {
t.Errorf("expected output to contain ' Second comment', got: %s", output)
}
}
func TestShowCommandNoComments(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "mint-issues.yaml")
t.Setenv("MINT_STORE_FILE", filePath)
store, _ := LoadStore(filePath)
issue, _ := store.AddIssue("Test issue without comments")
_ = store.Save(filePath)
cmd := newCommand()
var buf bytes.Buffer
cmd.Writer = &buf
err := cmd.Run(context.Background(), []string{"mint", "show", issue.ID})
if err != nil {
t.Fatalf("show command failed: %v", err)
}
output := stripANSI(buf.String())
if strings.Contains(output, "Comments") {
t.Errorf("expected output NOT to contain 'Comments' when no comments, got: %s", output)
}
}
func TestShowCommandWithRelationships(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "mint-issues.yaml")
t.Setenv("MINT_STORE_FILE", filePath)
store, _ := LoadStore(filePath)
issue1, _ := store.AddIssue("Main issue")
issue2, _ := store.AddIssue("Dependency issue")
issue3, _ := store.AddIssue("Blocked issue")
_ = store.AddDependency(issue1.ID, issue2.ID)
_ = store.AddBlocker(issue1.ID, issue3.ID)
_ = store.Save(filePath)
cmd := newCommand()
var buf bytes.Buffer
cmd.Writer = &buf
err := cmd.Run(context.Background(), []string{"mint", "show", issue1.ID})
if err != nil {
t.Fatalf("show command failed: %v", err)
}
output := stripANSI(buf.String())
if !strings.Contains(output, "Depends on") {
t.Errorf("expected output to contain 'Depends on', got: %s", output)
}
if !strings.Contains(output, " "+issue2.ID+" open Dependency issue") {
t.Errorf("expected output to contain ' %s open Dependency issue', got: %s", issue2.ID, output)
}
if !strings.Contains(output, "Blocks") {
t.Errorf("expected output to contain 'Blocks', got: %s", output)
}
if !strings.Contains(output, " "+issue3.ID+" open Blocked issue") {
t.Errorf("expected output to contain ' %s open Blocked issue', got: %s", issue3.ID, output)
}
}
func TestShowCommandNoRelationships(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "mint-issues.yaml")
t.Setenv("MINT_STORE_FILE", filePath)
store, _ := LoadStore(filePath)
issue, _ := store.AddIssue("Standalone issue")
_ = store.Save(filePath)
cmd := newCommand()
var buf bytes.Buffer
cmd.Writer = &buf
err := cmd.Run(context.Background(), []string{"mint", "show", issue.ID})
if err != nil {
t.Fatalf("show command failed: %v", err)
}
output := stripANSI(buf.String())
if strings.Contains(output, "Depends on") {
t.Errorf("expected output NOT to contain 'Depends on' when no dependencies, got: %s", output)
}
if strings.Contains(output, "Blocks") {
t.Errorf("expected output NOT to contain 'Blocks' when no blocks, got: %s", output)
}
}
func TestShowCommandWithRelationshipsAndComments(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "mint-issues.yaml")
t.Setenv("MINT_STORE_FILE", filePath)
store, _ := LoadStore(filePath)
issue1, _ := store.AddIssue("Main issue")
issue2, _ := store.AddIssue("Dependency")
issue3, _ := store.AddIssue("Blocked")
_ = store.AddDependency(issue1.ID, issue2.ID)
_ = store.AddBlocker(issue1.ID, issue3.ID)
_ = store.AddComment(issue1.ID, "Test comment")
_ = store.Save(filePath)
cmd := newCommand()
var buf bytes.Buffer
cmd.Writer = &buf
err := cmd.Run(context.Background(), []string{"mint", "show", issue1.ID})
if err != nil {
t.Fatalf("show command failed: %v", err)
}
output := stripANSI(buf.String())
dependsIdx := strings.Index(output, "Depends on")
blocksIdx := strings.Index(output, "Blocks")
commentsIdx := strings.Index(output, "Comments")
if dependsIdx == -1 {
t.Error("expected output to contain 'Depends on'")
}
if blocksIdx == -1 {
t.Error("expected output to contain 'Blocks'")
}
if commentsIdx == -1 {
t.Error("expected output to contain 'Comments'")
}
if commentsIdx != -1 && dependsIdx != -1 && commentsIdx < dependsIdx {
t.Errorf("Comments section should appear after Depends on section")
}
if commentsIdx != -1 && blocksIdx != -1 && commentsIdx < blocksIdx {
t.Errorf("Comments section should appear after Blocks section")
}
}
func TestShowCommandAlias(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "mint-issues.yaml")
t.Setenv("MINT_STORE_FILE", filePath)
store, err := LoadStore(filePath)
if err != nil {
t.Fatalf("failed to load store: %v", err)
}
issue, err := store.AddIssue("Test show issue")
if err != nil {
t.Fatalf("failed to add issue: %v", err)
}
if err := store.Save(filePath); err != nil {
t.Fatalf("failed to save store: %v", err)
}
cmd := newCommand()
var buf bytes.Buffer
cmd.Writer = &buf
err = cmd.Run(context.Background(), []string{"mint", "s", issue.ID})
if err != nil {
t.Fatalf("s alias command failed: %v", err)
}
output := stripANSI(buf.String())
if !strings.Contains(output, "ID "+issue.ID) {
t.Errorf("expected output to contain 'ID %s', got: %s", issue.ID, output)
}
if !strings.Contains(output, "Title Test show issue") {
t.Errorf("expected output to contain 'Title Test show issue', got: %s", output)
}
}
func TestShowCommandWithStaleRelationships(t *testing.T) {
tmpDir := t.TempDir()
filePath := filepath.Join(tmpDir, "mint-issues.yaml")
t.Setenv("MINT_STORE_FILE", filePath)
store, _ := LoadStore(filePath)
issue, _ := store.AddIssue("Issue with stale refs")
// Manually inject stale references
issue.DependsOn = []string{"stale-dependency"}
issue.Blocks = []string{"stale-blocker"}
_ = store.Save(filePath)
cmd := newCommand()
var buf bytes.Buffer
cmd.Writer = &buf
err := cmd.Run(context.Background(), []string{"mint", "show", issue.ID})
if err != nil {
t.Fatalf("show command should not fail on stale refs: %v", err)
}
output := stripANSI(buf.String())
// Check that stale refs are shown with (not found)
if !strings.Contains(output, "stale-dependency (not found)") {
t.Errorf("expected output to contain 'stale-dependency (not found)', got: %s", output)
}
if !strings.Contains(output, "stale-blocker (not found)") {
t.Errorf("expected output to contain 'stale-blocker (not found)', got: %s", output)
}
}