Skip to content

Commit 91795f7

Browse files
authored
update qascsv (#3)
* update qascsv - increase folder length, tcase title length - add type (standalone, template) - add custom fields support * fix - add custom field duplicate check - allow multiple requirements (backend already supports) * fix potential false negative test case * add more comments * fix gofumpt
1 parent fa6dfd5 commit 91795f7

File tree

2 files changed

+362
-40
lines changed

2 files changed

+362
-40
lines changed

qacsv_test.go

Lines changed: 203 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,18 @@ var successTestCases = []TestCase{
2727
Expected: "expected-2",
2828
},
2929
},
30-
Requirement: &Requirement{Title: "req1", URL: "http://req1"},
30+
Requirements: []Requirement{{Title: "req1", URL: "http://req1"}},
3131
Files: []File{
3232
{
33+
ID: "file-id",
3334
Name: "file-1.csv",
3435
MimeType: "text/csv",
3536
Size: 10,
3637
URL: "http://file1",
3738
}, {
3839
Name: "file-1.csv",
3940
ID: "file-id",
41+
URL: "http://file1",
4042
MimeType: "text/csv",
4143
Size: 10,
4244
},
@@ -70,9 +72,10 @@ var successTestCases = []TestCase{
7072
Expected: "expected.,<>/@$%\"\"''*&()[]{}+-`!~;",
7173
},
7274
},
73-
Requirement: &Requirement{Title: "req.,<>/@$%\"\"''*&()[]{}+-`!~;"},
75+
Requirements: []Requirement{{Title: "req.,<>/@$%\"\"''*&()[]{}+-`!~;"}},
7476
Files: []File{
7577
{
78+
ID: "file-id",
7679
Name: "file-1.csv",
7780
MimeType: "text/csv",
7881
Size: 10,
@@ -101,16 +104,18 @@ var successTestCases = []TestCase{
101104
Expected: "expected-2",
102105
},
103106
},
104-
Requirement: &Requirement{URL: "http://req1"},
107+
Requirements: []Requirement{{URL: "http://req1"}},
105108
Files: []File{
106109
{
110+
ID: "file-id",
107111
Name: "file-1.csv",
108112
MimeType: "text/csv",
109113
Size: 10,
110114
URL: "http://file1",
111115
}, {
112116
Name: "file-1.csv",
113117
ID: "file-id",
118+
URL: "http://file1",
114119
MimeType: "text/csv",
115120
Size: 10,
116121
},
@@ -120,11 +125,11 @@ var successTestCases = []TestCase{
120125
},
121126
}
122127

123-
const successTestCasesCSV = `Folder,Name,Legacy ID,Draft,Priority,Tags,Requirements,Links,Files,Preconditions,Step 1,Expected 1,Step 2,Expected 2
124-
root,tc-with-minimal-fields,,false,high,,,,,,,,,
125-
root,tc-with-partial-fields,,true,low,,[](http://req1),,"[{""file_name"":""file-1.csv"",""url"":""http://file1"",""mime_type"":""text/csv"",""size"":10},{""file_name"":""file-1.csv"",""id"":""file-id"",""mime_type"":""text/csv"",""size"":10}]",,action-1,,,expected-2
126-
root/child,tc-with-all-fields,legacy-id,false,high,"tag1,tag2",[req1](http://req1),"[link-1](http://link1),[link-2](http://link2)","[{""file_name"":""file-1.csv"",""url"":""http://file1"",""mime_type"":""text/csv"",""size"":10},{""file_name"":""file-1.csv"",""id"":""file-id"",""mime_type"":""text/csv"",""size"":10}]",preconditions,action-1,expected-1,action-2,expected-2
127-
root/child,"tc-with-special-chars.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;",legacy-id,false,high,"tag1.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;","[req.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;]()","[link-1.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;](http://link1)","[{""file_name"":""file-1.csv"",""url"":""http://file1"",""mime_type"":""text/csv"",""size"":10}]","preconditions.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;","action.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;","expected.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;",,
128+
const successTestCasesCSV = `Folder,Type,Name,Legacy ID,Draft,Priority,Tags,Requirements,Links,Files,Preconditions,Parameter Values,Template Suffix Params,Step 1,Expected 1,Step 2,Expected 2
129+
root,standalone,tc-with-minimal-fields,,false,high,,,,,,,,,,,
130+
root,standalone,tc-with-partial-fields,,true,low,,[](http://req1),,"[{""fileName"":""file-1.csv"",""id"":""file-id"",""url"":""http://file1"",""mimeType"":""text/csv"",""size"":10},{""fileName"":""file-1.csv"",""id"":""file-id"",""url"":""http://file1"",""mimeType"":""text/csv"",""size"":10}]",,,,action-1,,,expected-2
131+
root/child,standalone,tc-with-all-fields,legacy-id,false,high,"tag1,tag2",[req1](http://req1),"[link-1](http://link1),[link-2](http://link2)","[{""fileName"":""file-1.csv"",""id"":""file-id"",""url"":""http://file1"",""mimeType"":""text/csv"",""size"":10},{""fileName"":""file-1.csv"",""id"":""file-id"",""url"":""http://file1"",""mimeType"":""text/csv"",""size"":10}]",preconditions,,,action-1,expected-1,action-2,expected-2
132+
root/child,standalone,"tc-with-special-chars.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;",legacy-id,false,high,"tag1.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;","[req.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;]()","[link-1.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;](http://link1)","[{""fileName"":""file-1.csv"",""id"":""file-id"",""url"":""http://file1"",""mimeType"":""text/csv"",""size"":10}]","preconditions.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;",,,"action.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;","expected.,<>/@$%""""''*&()[]{}+-[BACKTICK]!~;",,
128133
`
129134

130135
var failureTestCases = []TestCase{
@@ -133,7 +138,7 @@ var failureTestCases = []TestCase{
133138
Folder: []string{"root"},
134139
Priority: "high",
135140
}, {
136-
Title: "very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-very-long-title-",
141+
Title: strings.Repeat("a", 512), // Exceeds 511 char limit
137142
Folder: []string{"root"},
138143
Priority: "high",
139144
}, {
@@ -161,17 +166,17 @@ var failureTestCases = []TestCase{
161166
Title: "long tag",
162167
Folder: []string{"root"},
163168
Priority: "high",
164-
Tags: []string{"very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very-long-tag-very"},
169+
Tags: []string{strings.Repeat("a", 256)}, // Exceeds 255 char limit
165170
}, {
166-
Title: "requirement without title and url",
167-
Folder: []string{"root"},
168-
Priority: "high",
169-
Requirement: &Requirement{},
171+
Title: "requirement without title and url",
172+
Folder: []string{"root"},
173+
Priority: "high",
174+
Requirements: []Requirement{{}},
170175
}, {
171-
Title: "requirement with invalid url",
172-
Folder: []string{"root"},
173-
Priority: "high",
174-
Requirement: &Requirement{URL: "ftp://req1"},
176+
Title: "requirement with invalid url",
177+
Folder: []string{"root"},
178+
Priority: "high",
179+
Requirements: []Requirement{{URL: "ftp://req1"}},
175180
}, {
176181
Title: "link without title and url",
177182
Folder: []string{"root"},
@@ -229,8 +234,159 @@ var failureTestCases = []TestCase{
229234
},
230235
}
231236

237+
// Custom field test data
238+
var customFields = []CustomField{
239+
{
240+
SystemName: "test_env",
241+
Type: CustomFieldTypeDropdown,
242+
},
243+
{
244+
SystemName: "automation",
245+
Type: CustomFieldTypeDropdown,
246+
},
247+
{
248+
SystemName: "notes",
249+
Type: CustomFieldTypeText,
250+
},
251+
}
252+
253+
var customFieldSuccessTestCases = []TestCase{
254+
{
255+
Title: "tc-with-single-custom-field",
256+
Folder: []string{"custom-fields"},
257+
Priority: "medium",
258+
CustomFields: map[string]CustomFieldValue{
259+
"test_env": {
260+
Value: "staging",
261+
IsDefault: false,
262+
},
263+
},
264+
},
265+
{
266+
Title: "tc-with-multiple-custom-fields",
267+
Folder: []string{"custom-fields"},
268+
Priority: "high",
269+
Tags: []string{"regression", "smoke"},
270+
CustomFields: map[string]CustomFieldValue{
271+
"test_env": {
272+
Value: "production",
273+
IsDefault: false,
274+
},
275+
"automation": {
276+
Value: "Automated",
277+
IsDefault: false,
278+
},
279+
"notes": {
280+
Value: "This is a test note with special chars: !@#$%^&*()",
281+
IsDefault: false,
282+
},
283+
},
284+
Steps: []Step{
285+
{
286+
Action: "Execute test",
287+
Expected: "Test passes",
288+
},
289+
},
290+
},
291+
{
292+
Title: "tc-with-empty-custom-field-value",
293+
Folder: []string{"custom-fields"},
294+
Priority: "low",
295+
CustomFields: map[string]CustomFieldValue{
296+
"notes": {
297+
Value: "",
298+
IsDefault: false,
299+
},
300+
},
301+
},
302+
{
303+
Title: "tc-with-default-custom-field",
304+
Folder: []string{"custom-fields"},
305+
Priority: "medium",
306+
CustomFields: map[string]CustomFieldValue{
307+
"automation": {
308+
Value: "",
309+
IsDefault: false,
310+
},
311+
},
312+
},
313+
{
314+
Title: "tc-with-all-fields-and-custom-fields",
315+
LegacyID: "CF-001",
316+
Folder: []string{"custom-fields", "comprehensive"},
317+
Priority: "high",
318+
Tags: []string{"custom", "comprehensive"},
319+
Preconditions: "Custom field test setup",
320+
Steps: []Step{
321+
{
322+
Action: "Step 1",
323+
Expected: "Result 1",
324+
},
325+
},
326+
Requirements: []Requirement{{Title: "CF Requirements", URL: "http://cf-req"}},
327+
Files: []File{
328+
{
329+
ID: "cf-file-id",
330+
Name: "cf-test.txt",
331+
MimeType: "text/plain",
332+
Size: 100,
333+
URL: "http://cf-file",
334+
},
335+
},
336+
Links: []Link{
337+
{
338+
Title: "CF Link",
339+
URL: "http://cf-link",
340+
},
341+
},
342+
Draft: false,
343+
CustomFields: map[string]CustomFieldValue{
344+
"test_env": {
345+
Value: "development",
346+
IsDefault: false,
347+
},
348+
"automation": {
349+
Value: "In Progress",
350+
IsDefault: false,
351+
},
352+
},
353+
},
354+
}
355+
356+
const customFieldSuccessTestCasesCSV = `Folder,Type,Name,Legacy ID,Draft,Priority,Tags,Requirements,Links,Files,Preconditions,Parameter Values,Template Suffix Params,Step 1,Expected 1,custom_field_dropdown_test_env,custom_field_dropdown_automation,custom_field_text_notes
357+
custom-fields,standalone,tc-with-single-custom-field,,false,medium,,,,,,,,,,"{""value"":""staging"",""isDefault"":false}",,
358+
custom-fields,standalone,tc-with-multiple-custom-fields,,false,high,"regression,smoke",,,,,,,Execute test,Test passes,"{""value"":""production"",""isDefault"":false}","{""value"":""Automated"",""isDefault"":false}","{""value"":""This is a test note with special chars: !@#$%^\u0026*()"",""isDefault"":false}"
359+
custom-fields,standalone,tc-with-empty-custom-field-value,,false,low,,,,,,,,,,,,"{""value"":"""",""isDefault"":false}"
360+
custom-fields,standalone,tc-with-default-custom-field,,false,medium,,,,,,,,,,,"{""value"":"""",""isDefault"":false}",
361+
custom-fields/comprehensive,standalone,tc-with-all-fields-and-custom-fields,CF-001,false,high,"custom,comprehensive",[CF Requirements](http://cf-req),[CF Link](http://cf-link),"[{""fileName"":""cf-test.txt"",""id"":""cf-file-id"",""url"":""http://cf-file"",""mimeType"":""text/plain"",""size"":100}]",Custom field test setup,,,Step 1,Result 1,"{""value"":""development"",""isDefault"":false}","{""value"":""In Progress"",""isDefault"":false}",
362+
`
363+
364+
var customFieldFailureTestCases = []TestCase{
365+
{
366+
Title: "tc-with-undefined-custom-field",
367+
Folder: []string{"custom-fields-errors"},
368+
Priority: "high",
369+
CustomFields: map[string]CustomFieldValue{
370+
"undefined_field": {
371+
Value: "some value",
372+
},
373+
},
374+
},
375+
{
376+
Title: "tc-with-very-long-custom-field-value",
377+
Folder: []string{"custom-fields-errors"},
378+
Priority: "medium",
379+
CustomFields: map[string]CustomFieldValue{
380+
"notes": {
381+
Value: strings.Repeat("a", 256), // Exceeds 255 char limit
382+
},
383+
},
384+
},
385+
}
386+
232387
func TestGenerateCSVSuccess(t *testing.T) {
233388
qasCSV := NewQASphereCSV()
389+
234390
for _, tc := range successTestCases {
235391
err := qasCSV.AddTestCase(tc)
236392
require.NoError(t, err)
@@ -271,3 +427,32 @@ func TestFailureTestCases(t *testing.T) {
271427
})
272428
}
273429
}
430+
431+
func TestCustomFieldSuccessTestCases(t *testing.T) {
432+
qasCSV := NewQASphereCSV()
433+
if err := qasCSV.AddCustomFields(customFields); err != nil {
434+
t.Fatalf("Failed to add custom fields: %v", err)
435+
}
436+
437+
for _, tc := range customFieldSuccessTestCases {
438+
err := qasCSV.AddTestCase(tc)
439+
require.NoError(t, err)
440+
}
441+
actualCSV, err := qasCSV.GenerateCSV()
442+
require.NoError(t, err)
443+
require.Equal(t, customFieldSuccessTestCasesCSV, actualCSV)
444+
}
445+
446+
func TestCustomFieldFailureTestCases(t *testing.T) {
447+
qasCSV := NewQASphereCSV()
448+
if err := qasCSV.AddCustomFields(customFields); err != nil {
449+
t.Fatalf("Failed to add custom fields: %v", err)
450+
}
451+
452+
for _, tc := range customFieldFailureTestCases {
453+
t.Run(tc.Title, func(t *testing.T) {
454+
err := qasCSV.AddTestCase(tc)
455+
require.NotNil(t, err)
456+
})
457+
}
458+
}

0 commit comments

Comments
 (0)